mIRC Homepage
Posted By: ScatMan regex help - 15/07/03 04:04 AM
what does the //o modifier and //c ?
and what does the m' and m!word! and m{word} ?

Posted By: ScatMan Re: regex help - 15/07/03 07:07 AM
and m"word"
Posted By: qwerty Re: regex help - 15/07/03 09:09 AM
/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.
Posted By: ScatMan Re: regex help - 15/07/03 09:51 AM
oh, thanks
so if i want to match "m" and it's in the begin i need to use \m ??
Posted By: qwerty Re: regex help - 15/07/03 10:04 AM
No, just make it a habit to use the default quotes ( "/" ) around the pattern: /m/
Posted By: ScatMan Re: regex help - 15/07/03 10:29 AM
uh.. yes, but why can't i use \m ??
Posted By: qwerty Re: regex help - 15/07/03 10:46 AM
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.
Posted By: ScatMan Re: regex help - 15/07/03 10:52 AM
ok
ty
Posted By: Hammer Re: regex help - 16/07/03 06:20 AM
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.
Posted By: ScatMan Re: regex help - 16/07/03 06:41 AM
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 ?

Posted By: qwerty Re: regex help - 16/07/03 07:32 AM
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:
Code:
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.
Posted By: qwerty Re: regex help - 16/07/03 07:48 AM
You need to use /m (multiline modifier) to make it work (ie $regex(abc $+ $lf $+ def,/^abc$/m). Here's what man.txt says:
Code:
     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).
Posted By: ScatMan Re: regex help - 16/07/03 11:51 AM
thx
© mIRC Discussion Forums