mIRC Home    About    Download    Register    News    Help

Print Thread
#104625 06/12/04 07:19 PM
Joined: Nov 2003
Posts: 67
C
Canario Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 67
//echo -a $regex(guest12343,/([0-9]){5}/) $regml(1)
In this case $regex returns 1 and $regml(1) the last match number (3)

//echo -a $regex(guest12343,/([0-9]){4,5}/) $regml(1)
1st question:
Why $regex returns 0 in the last example? it´s look like the 1st case only I change 5 times for 4 or 5 times.

2nd question: How I Can return the whole number and not only the last number match? (with $regml)


irc.universochat.net
#escripting
#104626 06/12/04 07:33 PM
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
As usual, when you're trying to pass a comma as a character in an identifier it needs to be escaped:

Code:
$regex(guest12343,$+(/([0-9]){4,$chr(44),5}/))


Or assign the expression to a local variable:

Code:
var %r = /([0-9]){4,5}/
echo -a $regex(string,%r)


In this case though, you can just change the expression slightly to erradicate the need for a {} quantifier:

Code:
echo -a $regex(string,/(\d{4}\d?)/)


Which also answers your second question, enclosing the whole part that matches the full number in parentheses i.e. ([0-9]{4,5}) instead of ([0-9]){4,5} will make it capture the whole number rather than the first one matched

#104627 06/12/04 07:35 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Both questions can be answered with the same answer smile
Put the {4,5} inside the ().

Code:
//echo -a $regex(guest12345,/(\d{4,5})/) $regml(1)


Just in case you were wondering, \d is the same as [0-9].


New username: hixxy
#104628 06/12/04 07:38 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
For some reason {N,N} doesn't need to be escaped.


New username: hixxy
#104629 06/12/04 07:50 PM
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
Not in all cases, just whenever the comma is enclosed in parentheses, (\d{4,5}) not (\d){4,5}, works this way with all identifiers. Check out $remove(a(,b,)c,(,b,))

#104630 06/12/04 07:55 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Oh, never knew about that, handy little feature. Thanks. smile


New username: hixxy
#104631 06/12/04 09:59 PM
Joined: Nov 2003
Posts: 67
C
Canario Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Nov 2003
Posts: 67
Thanks for the good explanation smile


irc.universochat.net
#escripting

Link Copied to Clipboard