From WikiChip
Editing mirc/regex
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 12: | Line 12: | ||
* --with-match-limit-recursion - 999 | * --with-match-limit-recursion - 999 | ||
− | The newline sequence | + | The newline sequence is the default $lf, it is the only accepted line separator. |
mIRC has four custom modifiers for regex: | mIRC has four custom modifiers for regex: | ||
Line 23: | Line 23: | ||
<source lang="mIRC"> | <source lang="mIRC"> | ||
− | ;$regexm(input,regex,Nth) | + | ;$regexm(input,regex,Nth) returns the Nth full match |
alias regexm { | alias regexm { | ||
noop $regex(full, $2, /^(?|m(.)?|(/)|^)(.*?)(?:\1(?!.*\1)(.*)$)?$/usD) | noop $regex(full, $2, /^(?|m(.)?|(/)|^)(.*?)(?:\1(?!.*\1)(.*)$)?$/usD) | ||
Line 56: | Line 56: | ||
=== Sanitizing the input === | === Sanitizing the input === | ||
− | If you pass value dynamically in a regex pattern, you have to escape any characters in such value that could | + | If you pass value dynamically in a regex pattern, you have to escape any characters in such value that could interpreted by the PCRE regex engine. |
− | Instead of escaping a bunch of characters | + | Instead of escaping a bunch of characters, PCRE allows for the \Q \E construct to not interpret anything between that construct: |
Looking for a match on a nickname such as nick[name], you could use /\b $+ \Q $+ $nick $+ \E\b/ | Looking for a match on a nickname such as nick[name], you could use /\b $+ \Q $+ $nick $+ \E\b/ | ||
Line 66: | Line 66: | ||
To solve the issue, you have to "escape" all the \E inside the value you're using: /b\Q $+ $replacecs($nick,\E,\E\\E\Q) $+ \E\b/ | To solve the issue, you have to "escape" all the \E inside the value you're using: /b\Q $+ $replacecs($nick,\E,\E\\E\Q) $+ \E\b/ | ||
− | + | Indeed, there's no way to escape a character inside the escaping sequence \Q\E, you have to first terminate the sequence yourself with \E, then you have to match the actual \E from the input with \\E, and then start a new escape sequence with \Q. | |
== Regex Identifiers == | == Regex Identifiers == | ||
Line 77: | Line 77: | ||
If the /g modifier is used, that number can be greater than 1. | If the /g modifier is used, that number can be greater than 1. | ||
− | You may see a negative value being returned if an error occured | + | You may see a negative value being returned if an error occured: |
− | |||
− | |||
− | |||
− | |||
* -8 - you reached the maximum number of backtracks allowed, for example: $regex($str(a,4000),(a+a+)*b) | * -8 - you reached the maximum number of backtracks allowed, for example: $regex($str(a,4000),(a+a+)*b) | ||
− | |||
* -21 - you reached an internal recursion limit, for example: $regex($str(a, 1000), (a)+) | * -21 - you reached an internal recursion limit, for example: $regex($str(a, 1000), (a)+) | ||
− | |||
=== $regml === | === $regml === | ||
Line 125: | Line 119: | ||
Special markers can be used inside the <subtext> parameter of $regsubex: | Special markers can be used inside the <subtext> parameter of $regsubex: | ||
− | * \0 - Returns the number of | + | * \0 - Returns the number of matches. |
* \n - Returns the current match number. | * \n - Returns the current match number. | ||
* \t - Returns the current match text (same as $regml(\n)). | * \t - Returns the current match text (same as $regml(\n)). |