mIRC Home    About    Download    Register    News    Help

Print Thread
#176972 17/05/07 05:14 PM
Joined: May 2007
Posts: 2
P
PeterUK Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
P
Joined: May 2007
Posts: 2
Hi there, I'm pretty new to regex. Basically what I'm trying to build is a Regex that can detect IRC nicknames in a given string. The problem is it only returns one match even if I put multiple matches within the string.

Here is my regex:
Code:
<[a-zA-Z0-9\x28\x29\x2D\x5B\x5C\x5D\x5F\x60\x7B\x7C\x7D]+>


This should return 3 matches from this string:
Code:
<name1> Haha <name2> Yes <name3> Indeed

but it only returns one match. What is wrong with my regex, I presume it's something very simple.

Thanks in Advance,
Peter

Last edited by PeterUK; 17/05/07 05:14 PM.
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Looks like you're not using the global flag on your expression, which is what tells it to find as many matches as possible instead of just one.

Your regex should look like this:

/<[a-zA-Z0-9\x28\x29\x2D\x5B\x5C\x5D\x5F\x60\x7B\x7C\x7D]+>/g


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: May 2007
Posts: 2
P
PeterUK Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
P
Joined: May 2007
Posts: 2
Thank you very much, that's exactly what I needed!


Link Copied to Clipboard