Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- negate a match in regex
November 27, 2008, 8:40 am
rate this thread
I have a script that I convert xml tags to html. like "<" I convert to
"<" and so on.
after the conversion I need to capture the information inside the tag.
let take for example the string "<abcd>: which is equivalent to
I tried to capture the "abcd" which can be different from tag to tag
in the following way:
like match "<" and then match anything that is not ">".
the thing is that it doesn't work on all tags for some reason and I
was wondering on a principal base if doing a [^somestring] suppose to
Re: negate a match in regex
No, using [^string] wont work as you're expecting. Just like
[string] doesn't match 'string' but only one of the letters s, t, r,
i, n, or g [^stirng] just matches one letter which isn't in 'string'.
What you need is a negative look-ahead (?!string). Read 'perldoc
perlre' for the explanation of it.
- » FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
- — Next thread in » PERL Discussions
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum