Regular Expressions

 

Regular expressions can be used to perform complicated pattern matching operations. You should already know how to use Regular expressions before using the identifiers below.

 

It is beyond the scope of this help file to explain how Regular Expressions work. There are many websites on the internet that introduce regular expressions and provide examples.

 

$regex([name], text, pattern)

Returns N, the number of strings in text that matched the regular expression pattern.

 

You can assign a name to a $regex() call which you can use later in $regml() to retrieve the list of matches.

 

If you do not specify a name, all identifiers use a 'default' name which is overwritten with each call to $regex().

 

$regml() remembers the results for the last fifty $regex() calls. Each time you do a match with $regex(), and you specify a name, that name's previous results are overwritten with the new results.

 

$regml([name], N)

This returns the Nth match returned by a call to $regex(), $regsub(), or $regsubex().

 

Properties: pos, group, match

 

If N = 0, returns total number of match strings.

 

The pos property returns a strings position in the original match text.

The group property returns the capture group number

The match property returns the match number in the case of a /g global match that returns multiple matches.

 

$regmlex([name], M, N)

If the /g modifier is used with a pattern, multiple results can be returned for that pattern. This identifier allows you to retrieve these results, where M is the Mth result and N is the () capture group number in that result. If N is not specified, it defaults to 1.

 

This identifier supports the same properties as $regml().

 

$regsub([name], text, pattern, subtext, %var|&binvar)

Performs a regular expression match, like $regex(), and then performs a substitution using subtext.

 

Returns N, the number of substitutions made, and assigns the result to %var or &binvar.

 

$regsubex([name], text, pattern, subtext, %var|&binvar)

Performs a regular expression match, like $regex(), and then performs a substitution using subtext.

 

Subtext is evaluated during substitution and can be an identifier.

 

Subtext can also contain special markers where \0 = number of matches, \n = match number, \t = match text, \a = all match items, and \A which is a non-spaced version of \a.

 

Returns text result.

 

Note: To output results to a %var|&binvar, the [name] parameter must be specified, and the identifier will return N, the same as $regsub().

 

$regerrstr

Returns the error string provided by the regular expression library for a failed evaluation.

 

Supported Modifiers

mIRC supports the following standard modifiers:

 

g - continue after first match

i - case insensitive match

m - multiple lines match

s - dot matches newlines

x - ignore white spaces

 

mIRC also supports the following modifiers:

 

A - anchored - match start of string

E/D - $ dollar matches only at end

U - ungreedy - reverses * and *?

u - enables UTF-8 and UCP

X - strict escape parsing

 

And the following mIRC-specific modifiers:

 

S - strip bold, underline, reverse, and color control codes

F - make back-references refer to () capture groups, which is how standard regex works.

 

Note: If the F modifier is not used, \N back-references in patterns and N indexes in identifiers refer to the order in which matches are found, and $regml() will not include empty matches.