Reputation: 10153
I`ve defined the following reg. expression using boost regex library
"([[:digit:]]{1,})([[:blank:]]*\\[label=\")([[:print:]]*)(\\([[:print:]]*\\)\\([[:print:]]+\\))(\"];)"
I use regex_search
to extract the data I am interested in match[3]
:
It succeeds for the following string with result MulOp
0 [label="MulOp( text1 )(depth =1)"];
But it fails for the below string and finds the result CALL( %text1
,when I want the result to be only CALL
8 [label="CALL( %text1(text2) text3 )(depth =2)"];
Can you advise me how to define general regex expression which will match the both cases
Upvotes: 0
Views: 107
Reputation: 76360
The problem comes from the "(text2)" in the target string. That adds a '('
character that isn't present in the first, so the ([[:print:]]*)
eats the first '('
. You need to exclude '('
from that first match. Replace it with something like ([^(]*)
if your syntax will always be the target name followed immediately by a '('
. Beyond that it's hard to say, because you haven't really defined what it is that you're looking for. (I won't trivialize this by suggesting that, with only two examples, matching what you want is trivial: just search for "MulOp" and "CALL" and if either one is there, return it)
Upvotes: 1