|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
what does the //o modifier and //c ? and what does the m' and m!word! and m{word} ?
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
/o and /c do not seem to do anything in PCRE. man.txt says nothing about them and I've never heard of them either.
When m is used as the very first character in a pattern, it defines the "quotes". Quotes are the characters that enclose the actual pattern, ie they are not used themselves in the matching process. For example the familiar /.../ are quotes: $regex(abc,/abc/). This regex can also be written like $regex(abc,abc). By default, the quote is the "/" character; the closing quote is the last "/" used. What m does is allow you to define your own character as quote. Fex: $regex(abc,mzabcz) is equivalent to $regex(abc,/abc/) : "m" makes "z" the quote character. $regex(ABC,mzabczi) is equivalent to $regex(ABC,/abc/i). You can see from the coloured parts that modifiers/options can be used normally when a different quote is specified.
m{word} matches "word}". m makes "{" the quote. "}" has no special meaning here, so m{word} is actually a quoted pattern that is missing the closing quote.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
oh, thanks so if i want to match "m" and it's in the begin i need to use \m ??
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
No, just make it a habit to use the default quotes ( "/" ) around the pattern: /m/
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
uh.. yes, but why can't i use \m ??
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
You can, $regex(m,\m) returns 1. I just wouldn't trust this so much. man.txt says that a "\<letter>" combination (ie a backslash followed by a letter) is considered the "<letter>" character, if this combo isn't already a special item (like \d, \t, \s, \D, \S, \w, \W etc). This behaviour changes with the /X modifier, which makes $regex error when a \<letter> sequence that is not a special item is used. This implies that if, in the future, \m is designed to do something special OR the /X option becomes default, your scripts that use \m will break.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
|
|
|
|
Joined: Dec 2002
Posts: 1,321
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,321 |
An explanation for those who are further curious about m/PATTERN[...o[/b][/color]sx. Bear in mind that this documentation is for Perl and how regular expressions are used there, not necessarily how PCRE (and thus mIRC) implements them. Even though some of that doesn't apply to mIRC, it's still kind of fun to know what all the options are, what they do, why they're there and how they might be used.
DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
another question, why this doesn't match: $regex(abc $+ $lf $+ def,^abc$) ? the tutorial says that $ match at the end of the string or before a line feed if u do $regex(abc $+ $lf,^abc$) it works, so why if u put something after the line feed it doesn't work ?
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
I read about quotes etc from the same perldoc page (though I'd completely forgotten about /c and /o) and the fact that PCRE man.txt says nothing about them is kinda annoying. Unfortunately, this is information that should be known, because a quote-related issue appears in /filter -g. It is known that modifiers do not work in /filter. What is not so well known is that /filter seems to repeatedly strip out anything that looks like quotes from the pattern. Here's an example that should help: alias filtertest {
write -c ftest.txt $+(rc1,$crlf,rc2,$crlf,rc3)
close -@ @@
window -C @@ -1 -1 300 200
if $1 == 1 { filter -fwg ftest.txt @@ /mim1rc1i/ }
elseif $1 == 2 { filter -fwg ftest.txt @@ mim1rc1i }
} The alias writes 3 lines of text in ftest.txt, first line is "rc1", second is "rc2, third is "rc3". /filtertest 1 grabs "rc3" and echoes it to the window @@, even though the pattern used is quite different. /filtertest 2 uses the second pattern and grabs "rc2" and "rc3". What mirc seems to do here is strip "m" and the quote characters from the pattern each time it checks a line of text. So, /filtertest 1 checks the 1st line, it strips the / / pair and the actual regex pattern is mim1rc1i. Moving on to the next line, it strips "mi" and the ending "i", so that the actual pattern is now m1rc1. Finally, it reaches the 3rd line, strips "m1" and "1" and makes the pattern rc, which of course matches "rc3". /filtertest 2 grabs "rc2" and "rc3" because it has one pair of quotes less (it lacks the / /'s), so the pattern becomes "rc" in the 2nd line instead of the 3rd.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
You need to use /m (multiline modifier) to make it work (ie $regex(abc $+ $lf $+ def,/^abc$/m). Here's what man.txt says:
A dollar character is an assertion which is true only if the
current matching point is at the end of the subject string,
or [color:blue]immediately before a newline character that is the last
character in the string (by default).[/color]
........
........
The meanings of the circumflex and dollar characters are
changed if the PCRE_MULTILINE option is set. When this is
the case, they match immediately after and immediately
before an internal newline character, respectively, in addi-
tion to matching at the start and end of the subject string.
For example, [color:blue]the pattern /^abc$/ matches the subject string
"def\nabc" in multiline mode, but not otherwise.[/color] Conse-
quently, patterns that are anchored in single line mode
because all branches start with ^ are not anchored in multi-
line mode, and a match for circumflex is possible when the
startoffset argument of pcre_exec() is non-zero. The
PCRE_DOLLAR_ENDONLY option is ignored if PCRE_MULTILINE is
set. The first blue part explains your second $regex() and the second part explains the first (doh).
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
|
|
|
|
|