Say I have the following string:
blah blah blah \the rain in sp\\\\ain moves mainly\\ on the p\\lain\\\\\ blah blah blah \ \\ \\ \\ \ foobar \ a\\b\\c\\ \
and I want to match the following 3 matches using grep:
\the rain in sp\\\\ain moves mainly\\ on the p\\lain\\\\\
and
\ \\ \\ \\ \
and
\ a\\b\\c\\ \
to do this I need a way to pair '\\' as to only end the match when there is a single closing '\' that isn't part of a pair.
so far I have this:
echo $string | grep -oP '\\((?!\\).)*\\'
edit: I managed to get it working in the regex101 environment:
\\((?!\\).|(([\\]{2})+))+\\
https://regex101.com/r/wC2cF1/13
but it's still giving me the same result in grep perl