mIRC Home    About    Download    Register    News    Help

Print Thread
#134856 05/11/05 04:15 PM
Joined: Sep 2004
Posts: 200
I
IR_n00b Offline OP
Fjord artisan
OP Offline
Fjord artisan
I
Joined: Sep 2004
Posts: 200
would anyone know how to make a regex, that catches things like:
Code:
somthing[!somechars]
abc[!xx]
ect[!gd]

my bot outputs it as nick[!stuff] even if stuff is null,
i tried making a regex, but it keeps screwing up on the [!stuff]
also, i would like it to allow [!stuff] to be there or not.
heres the regex i tried if it would help:
Code:
$regex(cmd2,%r,/\b((\w+)(?:\[([^\s]*)\])?)\b/m)

btw, the %r is in format: a[!b] c[!d] ect

#134857 05/11/05 11:28 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I don't really understand what your issue is.

Your regex matches on:

"something[!stuff]"
"something[!]"
"something"

Isn't that what you want?

Btw I don't really see a purpose, if you make the [!stuff] optional, then you're basically telling the regex it may match any sequence of \w chars = [a-zA-Z0-9_], as long as it's delimited with word boundaries. This is a pretty general match, and will practically match any regular string you throw at it.

Btw is "something[!stuff]" gonna be part of a larger string, or is that the only string etc. etc.
Do you intend to capture anything from the string, or do you solely want to know if the inputted string matches the regex criteria. Will "something" and "stuff" always be sctriclty alpha chars, or can there be others? in case there is "stuff" must it always be preceeded by an exlamation mark? What should the regex do if you input a string that has both "something" as it has "something[!stuff]". What should it do when you pass it "something[.bla]" should try to match the something, or should it discard it alltogether cuz the first letter inside the [ ] was not a ! but a .

You are going to have elaborate on this much more as we are not mind readers.


Gone.
#134858 06/11/05 06:05 AM
A
Anonymous
Unregistered
Anonymous
Unregistered
A
i recommend everyone trying to use regular expressions this small application "reg-ex coach" : http://weitz.de/files/regex-coach.exe

and also the documentation for the "grep" function in linux... (the part about regex)

#134859 06/11/05 12:53 PM
Joined: Jul 2005
Posts: 56
W
Babel fish
Offline
Babel fish
W
Joined: Jul 2005
Posts: 56
/\S+\Q[\E!\w*]/


Link Copied to Clipboard