mIRC Home    About    Download    Register    News    Help

Print Thread
K
kocam
kocam
K
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,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
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

K
kocam
kocam
K
Thanks. grin

I Forgot 2 things :\

- case unsensitive
- regml return for second word

Thanks again smile

Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
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.
K
kocam
kocam
K
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,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
You're welcome!

M
MIMP
MIMP
M
You might want to check out http://www.regular-expressions.info/ for help with learning regular expressions.

Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Note that you don't need to use $lower(), since $*tok() identifiers are not case-sensitive (their case-sensitive counterparts are the $*tokcs() identifiers).

Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
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.

Link Copied to Clipboard