开发者

Inverting a regex as a whole

开发者 https://www.devze.com 2023-04-06 03:16 出处:网络
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:

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:

  1. Perform "Match All" search with regular expression "^PHVS". This marked every line that started with PHVS

  2. Go to Edit -> Invert Bookmarks. This marked every line that did NOT start with PHVS

  3. Created a macro that pressed F2 (to go to next bookmark) and fix the line the way I needed it

  4. Ran the macro to the end of the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号