Inverting a regex as a whole
OK, I read thro开发者_开发百科ugh this thread and it hasn't helped me so far.
I have a regex in TextPad (not sure of its engine) like so:
[[:digit:]]+ \= [[:digit:]]+ \+ [[:digit:]]+
that finds a string such as:
1783635 = 1780296 + 3339
and I want to find everything else. I tried encasing the whole expression with [^ expression ]
as the TextPad manual says to do, with no luck. I also tried [^][ expression ]
, ^( expression )
, and [^]( expression )
, with no luck.
From the thread above, I tried (?! expression )
, again, with no luck.
Thoughts?
It is not really possible to match "the opposite of" with regex. Regular expressions must match to succeed, they cannot not match and still succeed.
Depending on your exact situation (and TextPad's regex capabilities), there might be a way around this limitation.
More detail is necessary to say that for sure, though. Please provide a real-world text sample and describe what you want to do with it.
The best way I have found to do this is not with JUST regular expressions, but to use additional functionality from TextPad (bookmarks).
In this case, I needed to identify all lines that did NOT start with PHVS. So I did the following:
Perform "Match All" search with regular expression "^PHVS". This marked every line that started with PHVS
Go to Edit -> Invert Bookmarks. This marked every line that did NOT start with PHVS
Created a macro that pressed F2 (to go to next bookmark) and fix the line the way I needed it
Ran the macro to the end of the file.
精彩评论