mIRC Home    About    Download    Register    News    Help

Print Thread
#22851 06/05/03 11:16 PM
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I'm getting very unusual results when using $hregex() without the .data property (searching Item names).

/hadd -m TEST aaa_mIRC_zzz
/hadd -m TEST bbb_MiRC_yyy
/hadd -m TEST ccc_MIrC_xxx
/hadd -m TEST ddd_MIRc_www
/hadd -m TEST eee_MIRC_vvv
/hadd -m TEST fff_mirc_uuu

//echo -a $hregex(TEST,//i,0) == 6 (correct)
//echo -a $hregex(TEST,/m/i,0) == 4 (should be 6)
"ccc_MIrC_xxx" "aaa_mIRC_zzz" "fff_mirc_uuu" "bbb_MiRC_yyy" (odd how it leaves out 'ddd' and 'eee')
//echo -a $hregex(TEST,/MIRC/i,0) == 2 (should be 6) "ccc_MIrC_xxx" "eee_MIRC_vvv"
//echo -a $hregex(TEST,/mirc/i,0) == 2 (should be 6) "ccc_MIrC_xxx" "fff_mirc_uuu"

I can't explain the behaviour of /i in $hregex. Sometimes it seems to only Lowercase for Uppercase matches, and sometimes it only seems to Uppercase for Lowercase matches... but not both?

- Raccoon on EFNet in #mIRC
Please contact if time permits.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Looks like a bug to me.

By the way, $hregex has been superceded by $hfind with the 'r' parameter (which also has the bug).


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Quote:
By the way, $hregex has been superceded by $hfind with the 'r' parameter

That's just sick. $hregex() is a fine name as is, and paves the way to $hregsub(). mad


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
Same thing with /filter -g.

It has been mentioned in the old board, but I don't remember if it was reported to this forum, and what caused it to happen.

The soltution is placing a (?i) in front of your pattern. For example,
Code:
//echo -a $hregex(TEST,/[color:brown](?i)[/color]m/,0)

Detailed information can be found in this reference, under the topic Internal Option Setting.

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
What exactly is (?i) suppose to do?
It appears to work, but will this mess up something else now? Will the use of ()'s create a back-reference, or is it the (? that prevents it from back-referencing?

- Raccoon

Added: Er, nevermind I overlooked your source as a signature line.

Last edited by Raccoon; 07/05/03 10:56 PM.

Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
(?A) is a Perl operator. It works similar to /A. Meaning (?i) means "case insensitive" just like /i means "case insensitive"

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
This problem exists since regex was implemented in mirc. It seems that mirc strips out the quotes from the regex pattern when you use $hregex() or /filter. Quotes in regex are the default slashes surrounding the actual pattern. Modifiers (like i and g) are used outside the pattern, ie after the closing quote, so they are stripped out too.

Any other pair of characters can be used as quotes too, using the letter "m" as a prefix. For example: $regex(abc,mu^abc$u) matches, because the "m" makes "u" a quote, so the actual pattern is between the 2 "u"'s. I've yet to find out how exactly mirc removes the quotes, but it seems that it does it repeatedly, with each call to $hregex or /filter.

For more on quotes etc, check this page. A lot of this info is irrelevant, but I remember finding some interesting things browsing perldoc.com. There are also differences between Perl regex and PCRE regarding the quotes (for example, Perl says that only non-alphanumerical characters can be used as quotes but in PCRE alnums seem to work as well).

I believe the safest solution is to take advantage of PCRE's internal options setting feature, as Online suggested.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
thank you, qwerty Online and codemastr. Very useful information from all.
(Except, I haven't been able to find (?A) or /A yet, and I'm unfamiliar with any regex prefixes, besides s/ which sadly has no use in mIRC.)

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
lol sorry I should have been more specific, I was using "A" to mean "alphabetic character" ie, a letter. I didn't mean there was actually a ?A or /A modifier smile


Link Copied to Clipboard