strmatch

Matches the target string with the regular expression.

Format

strmatch <target string> <string with regular expression>

Remarks

Supports Oniguruma Regular Expressions.
This command searches the <target string> with the <string with regular expression>.
The "strmatch" command returns one of the following values in the system variable "result":

Value Meaning
0 Not matched.
1 Matched offset(1origin).

The first matched pattern is stored in the system variable "matchstr".
Group matched patterns of regular expressions are stored in 9 system variables from "groupmatchstr1" to "groupmatchstr9".
Also, these system variables will not be changed when the pattern does not match.

When a user searches the multi-byte string like as Japanese, the user must configure the regular encoding by using the regexoption previously.

Example

strmatch 'Darwin Kernel [Version 21.6.0]' '\[(Version (\d+).(\d+).(\d+))\]'

int2str s result
messagebox s 'result'                        ; 15
messagebox matchstr 'matchstr'               ; [Version 21.6.0]
messagebox groupmatchstr1 'groupmatchstr1'   ; Version 21.6.0
messagebox groupmatchstr2 'groupmatchstr2'   ; 21
messagebox groupmatchstr3 'groupmatchstr3'   ; 6
messagebox groupmatchstr4 'groupmatchstr4'   ; 0

See also