mIRC Home    About    Download    Register    News    Help

Print Thread
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

Joined: Feb 2004
Posts: 2,019
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.
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

Joined: Feb 2004
Posts: 2,019
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.
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


Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You're welcome!


Gone.
Joined: Dec 2002
Posts: 102
M
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
Joined: Jan 2003
Posts: 2,523
Q
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
Joined: Feb 2004
Posts: 2,019
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.

Link Copied to Clipboard