mIRC Home    About    Download    Register    News    Help

Print Thread
Using regexps in script #136771 03/12/05 03:10 PM
Joined: Mar 2005
Posts: 39
B
bapplander Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Mar 2005
Posts: 39
Hello, i have two small regexps i would like to implement in a script.. It checks $2 for valid chars, and if not returtn..

Code:
on *:TEXT:!input *:#mychan: {
  [color:red]regexps[/color]
write mytext.txt $2
}


The regexps i want to use is {[regexp -all {\(} $2]!=[regexp -all {\)} $2]} and {[regexp {[^a-zA-Z0-9\(\)_.\-]} $2]} .
How do i use them? confused frown

Last edited by bapplander; 03/12/05 03:12 PM.
Re: Using regexps in script #136772 03/12/05 06:12 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Look at /help $regex for info on regular expressions. The syntax you are using looks like TCL. mIRC uses the PERL (proper) syntax for regex. For more info on the syntax, go here: http://www.regular-expressions.info

Looking at your example, it seems like you want to ensure that there are equal numbers of ( and ) characters. In mIRC you can do that easily like this:

if ($count($2,$chr(40)) != $count($2,$chr(41))) return

To check if there are any invalid characters, you can use this regex:

if ($regex($2,[^\w().-])) return

Just a note, certain characters don't need to be escaped when they are within [] brackets.

-genius_at_work

Re: Using regexps in script #136773 03/12/05 06:55 PM
Joined: Mar 2005
Posts: 39
B
bapplander Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Mar 2005
Posts: 39
Thanx dude, I'll have a look at it. smile

BTW; how can i check that ( always comes first before ) ?
like (hello) and not )hello( ?

Re: Using regexps in script #136774 03/12/05 07:09 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
//tokenize 32 (hello) | if ($regex($1,/^\50[\w.-]+\51$/)) echo -a match
//tokenize 32 )hello( | if ($regex($1,/^\50[\w.-]+\51$/)) echo -a match

The regex matches: (a-zA-Z0-9_-.) where the part in between brackets can be 1 or more consequent chars that match that criteria.


Gone.
Re: Using regexps in script #136775 03/12/05 07:23 PM
Joined: Mar 2005
Posts: 39
B
bapplander Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Mar 2005
Posts: 39
hm.. how do i use that in my script, though?
to check that ( always comes before ) in $2, and that it have to be atleast two chars within ( and ).. confused

Re: Using regexps in script #136776 03/12/05 07:33 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
if ($regex($2,/^\50(?:[\w.-]{2,})\51$/)) echo -a match

Btw, you should learn basic mIRC scripting first before trying regex, as you could have solved this fairly easy with regular scripting.


Gone.