正则表达式在公式中查找分隔符点

我使用的C#表达式库不会直接支持我的表/字段参数语法:

以下是不直接支持的表/字段参数名称:

TableName1.FieldName1 [TableName1].[FieldName1] [Table Name 1].[Field Name 1] 

它接受不带空格的字母数字参数,或大括号括在方括号内的大多数字符。 我想使用C#正则表达式将点分隔符和相邻括号替换为不同的分隔符,因此结果如下:

 [TableName1|FieldName1] [TableName1|FieldName1] [Table Name 1|Field Name 1] 

我还需要在单引号中跳过任何字符串文字,例如:

 'TableName1.FieldName1' 

当然,忽略任何数字文字,如:

 12345.6789 

编辑:感谢您就改进我的问题提出的反馈意见。 希望现在更清楚了。

我已经写了一个全新的答案,现在澄清了问题:

可以在一个正则表达式中执行此操作。 我认为这是非常防弹的,但正如你所看到的,它并不是完全不言自明的,这就是我自由评论它的原因。 希望它有意义。

你很幸运.NET允许重复使用命名捕获组,否则你将不得不分几步完成。

 resultString = Regex.Replace(subjectString, @"(?: # Either match... (? # (and capture into backref ) (?=\w*\p{L}) # (as long as it contains at least one letter): \w+ # one or more alphanumeric characters, ) # (End of capturing group ). \. # then a literal dot, (? # (now capture again, into backref ) (?=\w*\p{L}) # (as long as it contains at least one letter): \w+ # one or more alphanumeric characters. ) # (End of capturing group ) and end of match. | # Or: \[ # Match a literal [ (? # (now capture into backref ) [^\]]+ # one or more characters except ] ) # (End of capturing group ). \]\.\[ # Match literal ].[ (? # (capture into backref ) [^\]]+ # one or more characters except ] ) # (End of capturing group ). \] # Match a literal ] ) # End of alternation. The match is now finished, but (?= # only if the rest of the line matches either... [^']*$ # only non-quote characters | # or [^']*'[^']*' # contains an even number of quote characters [^']* # plus any number of non-quote characters $ # until the end of the line. ) # End of the lookahead assertion.", "[${before}|${after}]", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); 

希望你可以试试这个正则表达式: /(\w[0-9]* *)+/g这会过滤掉除了之外的所有字母数字。