Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Regex 正则表达式的正确性_Regex_Vb.net_String_.net 2.0 - Fatal编程技术网

Regex 正则表达式的正确性

Regex 正则表达式的正确性,regex,vb.net,string,.net-2.0,Regex,Vb.net,String,.net 2.0,我正在尝试创建一个正则表达式,它将匹配以下任一项- FVAL(A) FVAL("A") FVAL(A,B) FVAL("A",B) FVAL("A","B") FVAL(A,"B") FVAL(A,B,C) FVAL("A",B,C) FVAL("A","B",C) FVAL("A","B","C") FVAL("A",B,"C") FVAL(A,"B","C") 正则表达式- FVAL\s*\(\s*[“*]\s*\w+\s*[“*]\s*,*\s*[“*]\s*\w+\s*[“*]\s*,

我正在尝试创建一个正则表达式,它将匹配以下任一项-

FVAL(A)
FVAL("A")
FVAL(A,B)
FVAL("A",B)
FVAL("A","B")
FVAL(A,"B")
FVAL(A,B,C)
FVAL("A",B,C)
FVAL("A","B",C)
FVAL("A","B","C")
FVAL("A",B,"C")
FVAL(A,"B","C")
正则表达式-

FVAL\s*\(\s*[“*]\s*\w+\s*[“*]\s*,*\s*[“*]\s*\w+\s*[“*]\s*,*\s*,*\s*[“*]\s*\w+\s*[“*]\s*\)

这个正则表达式应该返回所使用函数的所有和任何形式

例如-
如果匹配字符串为-
FVAL(A,“B”)+5
,则匹配组应为
FVAL(A,“B”)

我忽略了匹配字符串中的空格,但它们可以存在。

你的表达式太复杂了

FVAL\("?\w+"?(?:,"?\w+"?){0,2}\)
细分:

FVAL # "FVAL" \( # "(" "? # an optional double quote \w+ # at least one word character "? # an optional double quote (?: # group , # a comma "?\w+"? # quote - word character - quote ){0,2} # end group, repeat 0-2 times \) # ")" FVAL#“FVAL” \( # "(" “?#可选双引号 \w+#至少一个单词字符 “?#可选双引号 (?:#组 一个逗号 “?\w+”?#引号-单词字符-引号 ){0,2}#端组,重复0-2次 \) # ")" 在您认为合适的表达式中插入空格。

您的表达式太复杂了

FVAL\("?\w+"?(?:,"?\w+"?){0,2}\)
细分:

FVAL # "FVAL" \( # "(" "? # an optional double quote \w+ # at least one word character "? # an optional double quote (?: # group , # a comma "?\w+"? # quote - word character - quote ){0,2} # end group, repeat 0-2 times \) # ")" FVAL#“FVAL” \( # "(" “?#可选双引号 \w+#至少一个单词字符 “?#可选双引号 (?:#组 一个逗号 “?\w+”?#引号-单词字符-引号 ){0,2}#端组,重复0-2次 \) # ")"
将空格
\s
插入到您认为合适的表达式中。

您的第六个示例
FVAL(“A,“B”)
,是否正确?(A)您的第六个示例
FVAL(“A,“B”)
,是否正确?(A)。解决了。正则表达式非常强大。@Soham如果你想确保引号是一致的,你可以用这个
(“?)\w+\1
代替
“?\w+”?
(其中
\1
必须是相应的组号)。这样,正则表达式在(且仅当)还有一个开始引号的情况下需要一个结束引号。我正在使用这个
FVAL\s*(\s*)“?\s*\w+\s*”?\s*(?:\s*,\s*“”?\s*\w+\s*“”?\s*){0,2}\”
。由于占用了空间,我无法使用
\1
。还有其他方法吗?
\s*
\1
有什么关系?这给了我一个错误,如果我使用
FVAL\s*\(\s*“”?\s*\w+\s*“”?\s*(?:\s*,\s*“”?\s*“”?\s*\s*\w+\s*\1\s*){0,2}\
。解决了。正则表达式非常强大。@Soham如果你想确保引号是一致的,你可以用这个
(“?)\w+\1
代替
“?\w+”?
(其中
\1
必须是相应的组号)。这样,正则表达式在(且仅当)还有一个开始引号的情况下需要一个结束引号。我正在使用这个
FVAL\s*(\s*)“?\s*\w+\s*”?\s*(?:\s*,\s*“”?\s*\w+\s*“”?\s*){0,2}\”
。由于占用了空间,我无法使用
\1
。还有其他方法吗?
\s*
\1
有什么关系?这给了我一个错误,如果我使用
FVAL\s*\(\s*“”?\s*\w+\s*“”?\s*(?:\s*,\s*“”?\s*“”?\s*\s*\w+\s*\1\s*){0,2}\,