I have a text and want to find some strings with regular expressions. My problem is i don’t know how to make “&&-and” here.
I have text like this:
AB " something is here;
and here...
";
...
AB "new line
continues ... ";
I want to find all AB, which end with “;
My code i use for “;” :
var matches = Regex.Matches(tmp, "(AB) ([^;]*);", RegexOptions.Singleline);
But how can i make "(AB) ([^(\";)]*)\";" or just "(AB) ([^(\"&&;)]*)(\"&&;") ?
I would like to have:
AB
" something is here;
and here ...
"
AB
"new line
continues ..."
^can only negate character classes, which in turn cannot contain strings of characters (but only single characters). However, there is a similar concept for strings of characters (or in fact full-fledged regular expressions) called a negative lookahead:This will now consume arbitrary characters (
.) as long as they do not mark the start of a";. Keep using theSinglelineoption, of course. You can do some reading on lookaround assertions here.