mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2006
Posts: 7
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Mar 2006
Posts: 7
Hi I have this regular expression:

//echo -a $regex(aa bb cc dd wujdkrufj%hufhuiref ee ff gg,/\s(.*?%.*?)\s/) | //echo -a $regml(1)

When executed it returns:
1
bb cc dd wujdkrufj%hufhuiref

The second .*? seems to be non-greedy as requested but the first one doesn't. Am I missing something?

Last edited by Oliver341; 04/01/07 03:25 PM.
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
I think it's vaguely explained here.

I believe what is happening is that it finds a space (\s), then repeats the '.' as few times as it can before finding a '%'. Which isn't the same as it finding the fewest characters to the left of the % before encountering a space (which is what you are expecting, I believe).

I guess one alternative that does what (I think) you want is:
Code:
/\s(\S*?%\S*?)\s/

or
Code:
/\b(\S*?%\S*?)\b/




Sais
Joined: Mar 2006
Posts: 7
O
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
O
Joined: Mar 2006
Posts: 7
Great, thanks for that Sais, you did understand what I was trying to do with my regular expression and your solution works as expected.

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
it is non greedy it starts at the first space and goes all the way to the first % which is what
\s.*?%

means

try

//echo -a $regex(aa aa%aa aa%asd sd,/(\S+?%\S+)/g) $regml(1) $regml(2)

EDIT: Seems i opened the reply window longer ago then i thought :P

Last edited by Mpdreamz; 04/01/07 05:29 PM.

$maybe

Link Copied to Clipboard