Using c# regex I’m trying to match things in quotes which aren’t also in brackets while also ignoring any white space:
"blah" - match
("blah") - no match
( "blah") - no match
( "blah") - no match
I’ve got (unescaped):
"(?<=[^(]\s")(.*?)"
which works with the first three but I can’t work out how to deal with more than one space between the first bracket and the quote. Using a + after the s is the same result, using a * means both the last two match. Any ideas?
This should work:
The first
(?<![^(\s])asserts that there is no whitespace or left parenthesis before the string.Then
\s*will match any number of whitespace characters.("[^"]*")will match a quoted string, and capture it’s content.\s*will match any number of whitespace characters.Last,
(?![\s)])will assert that there is no whitespace or right-parenthesis following.Together they make sure that all the whitespace is matched by each
\s*, and that they are not bordering a parenthesis.