TinyMARE HelpText

Global Functions > Regmatch()

Regmatch()

regmatch(<string>, <pattern>)
regmatch(<string>, <pattern>, <register>)

This function performs regular expression matching with <pattern> on <string>, returning 1 if there is a match or 0 if no match exists. The <pattern> may contain wildcards * and ?, but it must not begin with any boolean characters. The <pattern> is not case-sensitive.

This function has the side-effect of modifying the environment variables %0 through %9 with the text substituted by each wildcard in <pattern>. That is, the text matching the first * or ? becomes %0, the second becomes %1, and so on up through %9. Wildcards beyond %9 are not recorded but still determine whether a successful match takes place.

An optional <register> number from 0 to 9 can be specified. This determines the first environment variable to which the parser will begin recording matches.

If only the side-effect of the function is wanted, you can use [mid(x,0,0)] or [left(x,0)] to nullify the result.

Examples:

Command Displays
say Match=[regmatch(@set me=Dark,@set =)], env0=%0, env1=%1 You say, "Match=1, env0=me, env1=Dark"
say Match=[regmatch(Does not match,*k*)], env0=%0, env1=%1 You say, "Match=0, env0=, env1="
say [left(regmatch(abc def,* *,2),0)]env0=%0, env1=%1, env2=%2, env3=%3 You say, "env0=, env1=, env2=abc, env3=def"

Errors:

  • #-1 Invalid global register. - The <register> was not in the range 0 to 9.

See also: match(), setq(), setr()

From the TinyMARE Help command - Courtesy Gandalf

-- SluggyQBFreak - 03 Nov 2006
Topic revision: r1 - 03 Nov 2006, SluggyQBFreak
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiMARE? Send feedback