Page 1 of 1
Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 2:07 pm
by jwa
Hello
I'm thinking how should look a regular expression, which match a string, when it doesn't contain two chars when one char directly follows another. For example:
string "ab12c" should NOT be matched, because contain substring "12" ("2" directly follows "1"),
but
string "ab1c2" should be matched, because char "2" doesn't follow "1" directly (there are some trash between, in our example it is char "c").
[^12] doesn't work
[^1(?=2)] doesn't work
... doesn't work ;<
How to do it ?
Many thanks for reply.
Re: Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 2:39 pm
by jwa
I know now. If someone want to know that should be:
^(?:(?!12).)+$
Re: Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 3:24 pm
by prometheuzz
jwa wrote:I know now. If someone want to know that should be:
^(?:(?!12).)+$
You do as if it was your own, while someone else suggested it to you:
http://regexadvice.com/forums/thread/45618.aspx
Re: Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 3:51 pm
by jwa
I didn't say that I solved that alone, someone explained me that and I wrote answer here If someone else want to know how to do it.
Re: Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 4:24 pm
by prometheuzz
jwa wrote:I didn't say that I solved that alone, someone explained me that and I wrote answer here If someone else want to know how to do it.
Good to hear that.
My point was (or is): give credit where credit is due.
Re: Problem with match, when one char follow directly anotother.
Posted: Mon Aug 25, 2008 4:52 pm
by jwa
I dont't want to write another thread so that's my second question connected with the flex - fast lexical analyzer.
I'm doing something like that in flex file:
%%
(?:(?!12).)+ { do_something(); }
%%
and the flex print an ERROR: unrecognized rule
I have tested that expression in other utilities and that's 100% correct. So didn't flex recognize that expression.. ?
How match string that will be agree with this regular expression in flex ?
Are there any other possibilities to do that matching in flex?
Re: Problem with match, when one char follow directly anotother.
Posted: Tue Aug 26, 2008 1:55 am
by prometheuzz
This is a general regex forum. You'd better ask at the Flex mailing list:
https://lists.sourceforge.net/lists/listinfo/flex-help
Good luck.