mIRC Home    About    Download    Register    News    Help

Print Thread
\d in regex #191078 02/12/07 01:28 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
\d{4}

does that mean a 4 digit number?

if so, how can i make it so it can be a 1/2 digit number

Re: \d in regex [Re: pouncer] #191079 02/12/07 01:41 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
\d{1,2}

Or:

\d\d?

Re: \d in regex [Re: hixxy] #191080 02/12/07 01:48 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks hixxy. i have another problem with a code you gave me a while back

Code:
alias test {
  var %str = Tom Jones
  if ($regex(%str, /([A-Z][a-z]{2}) (?1)/)) { echo -a pass! }
}


i only want it to echo pass if the 2 words in the string are length 3 (and both words start with a caps letter), why does it echo 'pass' in the above case?

Last edited by pouncer; 02/12/07 01:49 AM.
Re: \d in regex [Re: pouncer] #191081 02/12/07 01:56 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
By default a regex matches anywhere in the string, so /b/ would still match "abc", because "b" is in the string.

To make an exact match you have to use the ^ and $ symbols:

/^b$/ will only match "b", nothing more nothing less.

So to apply that to your expression you'd use:

Code:
/^([A-Z][a-z]{2}) (?1)$/

Re: \d in regex [Re: hixxy] #191082 02/12/07 02:00 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thanks alot hixxy