I have to find all strings starting with //MARK that do not contain sting ABCDS. I had some trials but all failed. Biggest question here is to mark set A-B.
(\/\/[ ]*MARK[ \t]*[:]*[ \t]*[^\n(?P=ABCD)]*)
It should work with:
//MARK: MarABdasdsd
//MARK sthIsHere
But should not match:
//MARK: great marABCDE
I am able to find all cases but do not know how to remove this one. I can use only single regular expression. I am aware of many posts negate the whole regex pattern when negative lookaround doesn't work
Any ideas?
I assume you are coding in Swift that uses ICU regex flavor. It supports lookaheads, thus, the regex based on a tempered greedy token will work:
//[ ]*MARK[ \t]*:*[ \t]*(?:(?!ABCD)[^\n])*$
See the regex demo
The regex matches
// - two /[ ]* - 0+ spacesMARK - a literal word MARK[ \t]*:*[ \t]* - 0+ spaces or tabs followed with 0+ colons followed with 0+ tabs or spaces(?:(?!ABCD)[^\n])* - the tempered greedy token matching any non-newline symbol that does not start a ABCD sequence $ - end of string.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With