Reputation: 183
Hello this is my problem, and I would appreciate if you could help.
This is my regex: \"(.*?)\"
and my goal is to collect each word etc. within ""
.
If i check it against {$= "a=" "a" 0 @paramGet ", b=" "b" 0 @paramGet ", rezultat=" "a" 0
@paramGet "b" 0 @paramGet + $}
and collect all groups I get:
a= a , b= b ,rezultat= a b
but if check it against {$= "a=" "a" 0 @paramGet ", b\"=" "b" 0 @paramGet ", rezu\"ltat=" "a" 0
@paramGet "b" 0 @paramGet + $}
I get:
"a=" "a" ", b\" " " " 0 @paramGet " "ltat=" "a" "b"
This is my question: Is there any way to make regex recognize
a= a , b\"= b ,rezu\"ltat= a b
as whole?
Upvotes: 0
Views: 39
Reputation: 72884
There are two ways to do it:
You can check that the character preceding the opening and closing double quotes is not a backslash:
[^\\]\"(.*?[^\\])\"
Use a negative lookbehind regex:
(?<!\\)\"(.*?)(?<!\\)\"
where (?<!b)a
means a
not preceded with a b
.
The latter seems to work better because it also matches empty strings as well.
Upvotes: 2