mIRC Home    About    Download    Register    News    Help

Print Thread
need help with regular expressions #82159 06/05/04 07:01 PM
Joined: May 2004
Posts: 24
K
kocam Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: May 2004
Posts: 24
Hi, I am new on this forum.
I'd like to know how to make a $regex with a pattern that checks if:
- first word (required), is !add or !addme;
- second word (optional), if specified, is a or b.

sry 4 my bad english

Thanks smile

Re: need help with regular expressions #82160 06/05/04 07:10 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hello,

I'm fairly new to regex, so others may have a more optimized regex, though this worx fine:
Code:
  
if $regex($1-,/^!add(?:me)?(?:\s[ab])?$/) { do stuff }


Greetz


Gone.
Re: need help with regular expressions #82161 06/05/04 07:39 PM
Joined: May 2004
Posts: 24
K
kocam Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: May 2004
Posts: 24
Thanks. grin

I Forgot 2 things :\

- case unsensitive
- regml return for second word

Thanks again smile

Re: need help with regular expressions #82162 06/05/04 08:10 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

Code:
 
if $regex($1-,/^!add(?:me)?(\s[ab])?$/i) { echo -a $regml(1) | ... }


So as you can see, due to the /i the match is case insensitive, and when the second letter (a or b) is matched, the match will be stored in $regml(1)

So 3 possibilities:

1) regex doesn't match
2) regex matches, but only on !add or !addme, so $regml(1) will be empty as there is no 2nd parameter (a or b) given
3) regex matches, with the 2nd parameter (a or b) which is stored in $regml(1)

Note that i used the echo command simply as an example.


Greetz


Edit: Note that you don't even need a regex to do what you want, although the regex is a little tidier. You could do:
Code:
 
if $istok(!add !addme,$lower($1),32) {
  if $istok(a b,$lower($2),32) { ... }
  else { ... }
}

Well you see where I'm going with this smile


Last edited by FiberOPtics; 06/05/04 08:42 PM.

Gone.
Re: need help with regular expressions #82163 06/05/04 09:32 PM
Joined: May 2004
Posts: 24
K
kocam Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: May 2004
Posts: 24
I know i can make script work without ER but I just want start learning them with some easy tutorials...

Anyway, thank u for the time spent on my problems grin


Re: need help with regular expressions #82164 06/05/04 09:37 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You're welcome!


Gone.
Re: need help with regular expressions #82165 06/05/04 10:45 PM
Joined: Dec 2002
Posts: 102
M
MIMP Offline
Vogon poet
Offline
Vogon poet
M
Joined: Dec 2002
Posts: 102
You might want to check out http://www.regular-expressions.info/ for help with learning regular expressions.


-
MIMP
Re: need help with regular expressions #82166 07/05/04 12:59 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Note that you don't need to use $lower(), since $*tok() identifiers are not case-sensitive (their case-sensitive counterparts are the $*tokcs() identifiers).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: need help with regular expressions #82167 07/05/04 01:31 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Yep,

didn't think of it...but well as he stated he wanted the regex anyway, was merely an example typed out the back of my head.

But right is right smile

So:
Code:

if $istok(!add !addme,$1,32) {
  if $istok(a b,$2,32) { ... }
  else { ... }
}

Greetz


Last edited by FiberOPtics; 07/05/04 01:34 AM.

Gone.