| Author |
inverting regular expression
|
manuel aldana
Ranch Hand
Joined: Dec 29, 2005
Posts: 308
|
|
hi, i am using following regex to "invert" a pattern (in python): pattern=[^b][^a][^r] this gets a bit difficult to read if "inverted" words are getting longer. is there a meta symbol so it possible to write: ~(bar) which matches all pattern bits which do not contain bar. thanks. [ April 17, 2006: Message edited by: manuel aldana ]
|
aldana software engineering blog & .more
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18641
|
|
[manuel]: this gets a bit difficult to read Also, it doesn't work. For example, the pattern [^b][^a][^r] match "xbar" (1st char is not b, 2nd char is not a, 3rd char is not r), and it won't match "boo" or "cat". (Because of the b in "boo" and the a in "cat", respectively.) I believe you want something using negative lookahead, like pattern=(?!.*bar) This matches only if it is not (!) possible to find "bar" after skipping an unknown number of characters (.*). Hope that helps...
|
"I'm not back." - Bill Harding, Twister
|
 |
manuel aldana
Ranch Hand
Joined: Dec 29, 2005
Posts: 308
|
|
autsch, stupid mistake from my side. thank you.
|
 |
 |
|
|
subject: inverting regular expression
|
|
|