开发者

Unable to figure out regex pattern

开发者 https://www.devze.com 2023-04-09 13:17 出处:网络
I have a string with some custom formula like FVAL(\"A\")+FVAL(B). I want to figure out all string inside FVAL() which does not have quotes around it.

I have a string with some custom formula like FVAL("A")+FVAL(B). I want to figure out all string inside FVAL() which does not have quotes around it.

So basically I want to extract out B because it does not have quotes a开发者_开发百科round it.


Use

FVAL\(([^")]*)\)

This matches FVAL(, followed by any number of characters except quotes or closing parentheses, followed by ).

Another possibility (where the match would be in $0 instead of $1:

(?<=FVAL\()[^")]*(?=\))

This matches a non-quote/non-parenthesis-string that is surrounded by FVAL( and ).

In VB.net:

Dim RegexObj As New Regex("FVAL\(([^"")]*)\)", RegexOptions.IgnoreCase)
Dim MatchResult As Match = RegexObj.Match(SubjectString)
While MatchResult.Success
    ResultList.Add(MatchResult.Groups(1).Value)
    MatchResult = MatchResult.NextMatch()
End While

or

Dim RegexObj As New Regex("(?<=FVAL\()[^"")]*(?=\))", RegexOptions.IgnoreCase)
Dim MatchResult As Match = RegexObj.Match(SubjectString)
While MatchResult.Success
    ResultList.Add(MatchResult.Value)
    MatchResult = MatchResult.NextMatch()
End While


You'll want an expression something like

"FVAL\\(([^\"]+)\\)"

which includes a set of parentheses for the capture group.

0

精彩评论

暂无评论...
验证码 换一张
取 消