mIRC Homepage
Posted By: PeterUK Regex Difficulties - 17/05/07 05:14 PM
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
Posted By: starbucks_mafia Re: Regex Difficulties - 17/05/07 06:17 PM
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
Posted By: PeterUK Re: Regex Difficulties - 17/05/07 06:49 PM
Thank you very much, that's exactly what I needed!
© mIRC Discussion Forums