mIRC Home    About    Download    Register    News    Help

Print Thread
regex help #38731 28/07/03 02:16 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
$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



Re: regex help #38732 28/07/03 02:35 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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 *.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: regex help #38733 28/07/03 02:57 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
thx
i'm probably don't know how the negative lookahead works
can u explain me ?

Re: regex help #38734 28/07/03 03:14 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
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.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: regex help #38735 28/07/03 03:31 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
don't understand frown

Re: regex help #38736 28/07/03 09:21 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: regex help #38737 29/07/03 05:15 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
what are assertions?

Re: regex help #38738 29/07/03 05:25 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Re: regex help #38739 29/07/03 05:26 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
uh, so what is so hard about them ?

Re: regex help #38740 29/07/03 05:30 PM
Joined: Dec 2002
Posts: 2,809
C
codemastr Offline
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Re: regex help #38741 29/07/03 05:35 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
uh.. ok thx

Re: regex help #38742 30/07/03 12:32 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com