mIRC Homepage
Posted By: lindenkron [Quickie] What's wrong with this regex? - 03/01/14 03:06 PM
Code:
%count = $regex($1-,/\bLion\b|\bTiger\b/g)


It registers Lion when you type 'lion' alone, but not 'tiger' when you type it alone. Other than that it works fine.

Thanks.
Posted By: Iire Re: [Quickie] What's wrong with this regex? - 04/01/14 02:54 AM
It should not match lion because regex is by default case sensitive... Are you sure you didn't type Lion?

You can make the regex case insensitive by adding the i modifier -- as it stands now, your pattern would match Tiger but not tiger or any other variation in case.

As a minor side note, \b will match things you may not want in front of a word, such as punctuation (e.g. ?tiger?), so it'd probably be preferable to use something more specific like (?:^|\s) instead:

Also, why not place lion and tiger in a group (non-capturing if you prefer), and put the (?:^|\s) and \b outside the group?

Code:
%count = $regex($1-,/(?:^|\s)(?:lion|tiger)\b/gi)
Thanks for your reply Lire.

It is meant to be case sensitive, I did not write Tiger and Lion with capital. Minor detail I didn't see, sorry.

I simply need both of them to be detected if typed alone - whereas now only one of them is (The first one).

I'm not good with regex, I'm quite confused as to what exactly you wrote there in your example! smile Thanks.
I tried swapping it out with what you wrote. And it does the same thing. "Lion" works but "Tiger" doesn't. It's always the 2nd one that doesn't work.
Code:
%count = $regex($1-,/(?:^|\s)(?:Lion|Tiger)\b/g)


Edit: I think I found out where the actual problem is:
Code:
on $*:TEXT:/Tiger|Lion/:#:


What's wrong there? frown
Hi. Little continuation.

Using
Code:
$regex($1-,/(?:^|\s)(?:Lion|Tiger)\b/g)


How do I make it accept the word if there's anything else next to it except for "\s Matches the space bar character : $regex(test this\s)" (Space bar). What if I want it to match "-Tiger" as well?

Thanks!

Edit: What would help me the best would probably be if someone could break down exactly how that regex works as well (the one I posted) so I can learn something! smile
Explain, in English, what you want to match and what you don't want to match. Provide the exact input and your expectation.

And do you actually need a count of the matches?
© mIRC Discussion Forums