mIRC Home    About    Download    Register    News    Help

Print Thread
#162391 17/10/06 03:07 PM
Joined: Oct 2006
Posts: 14
H
hero12 Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2006
Posts: 14
For the sake of neatness I would like to see a PERL-like regex operator =~ and of course the negative would be !=~
This doesn't have any new functional benefit since it does no more than what $regex does.

For new functionality I propose $regexex that works in a similar manner to $regsubex in that it returns a text result. For example $regexex(abcde, /(b..)/) would return bcd. I have cursed mirc many times for making me do if($regex()) $regml()

#162392 17/10/06 03:15 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
A regex operator has been suggested before and i concur that it would be nice. However if ($regex()) is pretty clear to the eye as well so other then the odd few byte saved it has no real value.

Your $regexex can be easily scripted but to implement in mIRC i personally don't see the use because how would it react when you have more then 1 capture ?


$maybe
#162393 17/10/06 03:37 PM
Joined: Oct 2006
Posts: 14
H
hero12 Offline OP
Pikka bird
OP Offline
Pikka bird
H
Joined: Oct 2006
Posts: 14
Quote:
Your $regexex can be easily scripted but to implement in mIRC i personally don't see the use because how would it react when you have more then 1 capture ?

Perhaps the same as \a does in substitution...

Also just returning the first match is useful too, like $ifmatch returns the first expression of an if statement but ignores the rest, that is still fantastically useful. If it were necessary to reference all parts of an if then we would have more than $v1 and $v2, there would be $v3 to $vN.

Last edited by hero12; 17/10/06 03:43 PM.
#162394 18/10/06 08:28 AM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
so you want
if ($regexex(abcd,/^(abcd)$/)) $v1 was matched
as suppose to
if ($regex(abcd,/^(abcd)$/)) $regml(1) was matched

Personally i hardly see the added value.


$maybe
#162395 18/10/06 05:48 PM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
I believe he'd rather want:

$regexex(abcd,/^(abcd)$/) was matched

No /if involved, no $regml() either, just a single identifier - which would be like one of the differences between $regsub and $regsubex.

However, the major difference between $regsub and $regsubex is the subtext in the latter being evaluated during substitution and being able to be an identifier. This has no place or purpose in $regex. Well, I don't think a $regexex is needed if all you want is to avoid an /if statement.

Last edited by cold; 18/10/06 05:51 PM.
#162396 18/10/06 05:59 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
samething really :tongue: Using it like that is not desireable though, what if it doesn't match ? you'd get a blank or 0 whatever the identifier would return.
In almost all cases you'd have to do an /if anyway.


$maybe
#162397 21/10/06 01:54 PM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Quote:
samething really :tongue: Using it like that is not desireable though, what if it doesn't match ? you'd get a blank or 0 whatever the identifier would return.
In almost all cases you'd have to do an /if anyway.


Well, if it was like $regsubex (without the substituting part), it'd simply return the same input string. It'd be the same kind of situation that leads you to never mind an /if when using $regsubex: you'd presuppose you don't need to check if the regex matches. It seems this is more like a preference than something useful.

I prefer using /if, though.


* cold edits his posts 24/7
#162398 21/10/06 03:06 PM
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
mpdreamz had a point, what if expression failed to match the string? obviously i'd expect $null to be returned, nothing else would make sense since any string could be matched by a capturing group in a regex. but $regml(N) itself could return $null even when the match was successful and the Nth back reference exists

Code:
//echo -a $regex(abc,/(x?)abc/) * $regml(0) * $len($regml(1))


maybe for your specific purpose it wouldnt matter if the expression was matched and $null captured as $regml(1) or if it didn't match at all, but since there would be no immediate way to determine this from $regexex, i dont think it would make a very 'complete' addition to mirc :x its definitey, imo, something that's better left as a custom identifier


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
#162399 21/10/06 06:33 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Its not really to same regsubex is used to replace bits in the input string if nothing was replaced it's only natural to return the unmodified input string. $regex is used to test if something matches. You cant compare your request with $regsubex because they just dont do the same thing. What you want lays somewhere in between but it's not clear what it should return. There's just no safeway of doing it.

//echo -a $regexex(abc,/(.)/g)
should return a b ca b ca b c because you want it to behave like \a in regsubex or abc if nothing matches because that was the input string.

That is what your saying but this seems very impractical and very close to useless to me. What you most likely want (though im guessing here so dont shoot me) is for it to behave like $regexex(text,re,C) returning a tokenized list of all the matches it made or $null if nothing was matched. Now i can see a use for that.


$maybe
#162400 22/10/06 05:50 AM
Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Well, that's exactly what I said, but that's better said. hehe


Link Copied to Clipboard