mIRC Homepage
Posted By: ScatMan regex help - 28/07/03 02:16 PM
$regex(*abd*,\*(?!abc)\*)
what's wrong? i'm trying to match inside the *'s something with 3 letters or less that is not equal to abc


Posted By: starbucks_mafia Re: regex help - 28/07/03 02:35 PM
The correct code would be
var %re = \*(?!abc)(.{0,3})\*
echo -a $regex(*abd*,%re)

Obviously you don't have to echo the result, but you do have to assign the regex pattern to a variable first since it contains a comma.

Your current pattern is saying:
- Match any string that contains a * that is not followed by 'abc', followed by another *. So in other words it will only match the string '**'.
What my pattern is saying is:
- Match any string that contains a * that is not followed by 'abc', followed by 0 to 3 characters, followed by another *.
Posted By: ScatMan Re: regex help - 28/07/03 02:57 PM
thx
i'm probably don't know how the negative lookahead works
can u explain me ?
Posted By: starbucks_mafia Re: regex help - 28/07/03 03:14 PM
I think you were expecting the lookahead assertion to match the characters following '*' if they weren't 'abc'. That's not how it works. All it does is create a condition that must be met in order for the preceding part of the pattern (the '*') to be matched.

Your pattern "looked" at the string, saw that the '*' wasn't followed by 'abc', and so it matched the '*' and moved on to the next part of the pattern. The next part of the pattern said to match another '*', but in the string we're only up to the 'a' in 'abd', so it failed to match.

I doubt that helped you understand lookahead assertions, but that's the best that I can explain it.
Posted By: ScatMan Re: regex help - 28/07/03 03:31 PM
don't understand frown
Posted By: qwerty Re: regex help - 28/07/03 09:21 PM
Heh, assertions are probably the hardest thing to explain to somebody. They are not particularly complicated themselves and are extremely useful but you just can't explain them without getting the answer "huh??". I think the only way to really understand how they work is by oneself.
Posted By: ScatMan Re: regex help - 29/07/03 05:15 PM
what are assertions?
Posted By: codemastr Re: regex help - 29/07/03 05:25 PM
Assertions are things that you are testing the truth of. For example, the \w assertion checks the truth of "the next character is a word character" if it is, the assertion succeeds, if it's not, the assertion fails.
Posted By: ScatMan Re: regex help - 29/07/03 05:26 PM
uh, so what is so hard about them ?
Posted By: codemastr Re: regex help - 29/07/03 05:30 PM
Well specifically look ahead/behind assertions are more confusing than that example. But I personally don't find assertions in general to be difficult. I find them to be very easy really, doing \W is much easier than doing [^[:word:]] for example.
Posted By: ScatMan Re: regex help - 29/07/03 05:35 PM
uh.. ok thx
Posted By: qwerty Re: regex help - 30/07/03 12:32 AM
Erm, \w or \W have nothing to do with assertions. The fundamental difference of assertions and stuff like [[:word:]], [^[:word:]], \w, \W etc is that the former are non-consuming items, while the latter are the opposite. \w "consumes" the part of the input it matches, so it cannot be used again for matching. Assertions, on the other hand, take a peek at the input string, either forward or backward (lookahead and lookbehind), and 'assert' the presence or absense (positive or negative) of certain features in the string, without "eating" those parts of the string themselves, so that regular (consuming) items can do that.
© mIRC Discussion Forums