mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
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.

Joined: Aug 2013
Posts: 81
I
Babel fish
Offline
Babel fish
I
Joined: Aug 2013
Posts: 81
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)

Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
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.

Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
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

Last edited by lindenkron; 05/01/14 11:30 AM.
Joined: Nov 2013
Posts: 49
L
Ameglian cow
OP Offline
Ameglian cow
L
Joined: Nov 2013
Posts: 49
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

Last edited by lindenkron; 14/01/14 12:47 AM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
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?


Link Copied to Clipboard