Problem with match, when one char follow directly anotother.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jwa
Forum Newbie
Posts: 4
Joined: Mon Aug 25, 2008 2:04 pm

Problem with match, when one char follow directly anotother.

Post 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.
jwa
Forum Newbie
Posts: 4
Joined: Mon Aug 25, 2008 2:04 pm

Re: Problem with match, when one char follow directly anotother.

Post by jwa »

I know now. If someone want to know that should be:
^(?:(?!12).)+$
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Problem with match, when one char follow directly anotother.

Post 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
jwa
Forum Newbie
Posts: 4
Joined: Mon Aug 25, 2008 2:04 pm

Re: Problem with match, when one char follow directly anotother.

Post 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.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Problem with match, when one char follow directly anotother.

Post 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.
jwa
Forum Newbie
Posts: 4
Joined: Mon Aug 25, 2008 2:04 pm

Re: Problem with match, when one char follow directly anotother.

Post 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?
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Problem with match, when one char follow directly anotother.

Post 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.
Post Reply