in reply to Parsing with regex
$check = "AND=>1536463OR<foobarOR=5";
Sorry for this mistake.
Li Tin O've Weedle
mad Tsort's philosopher
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parsing with regex
by demerphq (Chancellor) on Sep 04, 2001 at 02:57 UTC | |
I have a few thoughts though, which i guess ill start with the regex that you used to describe your data, and the sample data you provided. My first question comes from looking at the two together. Your regex describes some of the following strings: I think my point is taken. :-) So then we look at the data. You didnt really say what was supposed to happen. IS this supposed to produce the following triplets Or was it supposed to reject it? (Its not clear from the conversation I saw on the chatterbox, nor from your post) So going back to my first point I assume that you nead to handle the basic relational operators? ie = => =< == > < >= <= != <> Off the top of my head that becomes (=[><=]?|[><]=?|!=|<>) So then we already have the first part, (AND|OR), which leaves the last. Now this comes my second intrepretation of your question. How do I keep .* from eating more than it should?
The way to solve this is figure out what the dot SHOULDNT match. Ie it shouldnt match the above regex combined together, (AND|OR)(=[><=]?|[><]=?|!=|<>), although we dont want to invoke capture buffers so we use (?:) instead of (), because that would be a new token. So we have to make sure char by char that we dont match that pattern. So the inner layer looks like:
(?!(?:AND|OR)(?:=[><=]?|[><]=?|!=|<>)).
We then wrap that again to say 1 or more of the above.. Note the OR in my version of your example. The rgex does not trip up over this because we made the negative lookahead assertion include the => coditional part as well. Hope this helps Yves
--
Update
| [reply] [d/l] [select] |
|
Re: Re: Parsing with regex
by LiTinOveWeedle (Scribe) on Sep 04, 2001 at 04:38 UTC | |
I am sorry for my poor problem describing. But you are totally right. Your work is great. This is what I really want. So no other description of my problems needed now. Thanks
Li Tin O've Weedle | [reply] |