Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正则表达式模式[TableName]。[FieldName]_C#_Regex_String - Fatal编程技术网

C# 正则表达式模式[TableName]。[FieldName]

C# 正则表达式模式[TableName]。[FieldName],c#,regex,string,C#,Regex,String,我有一个计算字段的字符串,其中包含字段、运算符、函数等。 我需要从这个字符串中提取字段。字段的格式为:[TableName].[FieldName],其中TableName和FieldName包含空格。 我用正则表达式解决了TableName和FieldName不带空格的问题: List<string> fieldsFound = new List<string>(); string pattern = @"\[(\w*)(\])(\.)(\[)(\w*)

我有一个计算字段的字符串,其中包含字段、运算符、函数等。 我需要从这个字符串中提取字段。字段的格式为:[TableName].[FieldName],其中TableName和FieldName包含空格。 我用正则表达式解决了TableName和FieldName不带空格的问题:

    List<string> fieldsFound = new List<string>();
    string pattern = @"\[(\w*)(\])(\.)(\[)(\w*)(\])";
    foreach (Match match in Regex.Matches(formula, pattern))
    {
        fieldsFound.Add(match.Value);
    }
List fieldsFound=new List();
字符串模式=@“\[(\w*)(\])(\.)(\[)(\w*)(\])”;
foreach(正则表达式中的Match.Matches(公式、模式))
{
fieldsFound.Add(匹配值);
}
所以,我需要一个模式,可以允许在TableName和FieldName中使用空格。
谢谢

\w
\s
放入字符类,以便匹配单词和空格字符

\[([\w\s]*)(\])(\.)(\[)([\w\s]*)(\])

如果不想捕获
[]
中的前导空格和尾随空格,请使用下面的正则表达式

\[\s*([\w\s]*?)\s*\]\.\[\s*([\w\s]*?)\s*\]

卓越!我不需要在[]中添加尾随空格。第一个解决方案就是我需要的。