$MATCH (check string)
$MATCH evaluates the characters used in a character string, and returns the number of characters up to but not including the first character that does not match.
Syntax
return-value=$MATCH(character-string,evaluation-format)
Values
-
return-value
Specifies the name of the variable into which the number of characters that matched evaluation-format is set. If no characters match, a 0-byte character string is returned.
-
character-string
Specifies the character string to be evaluated, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
-
Specifies, as a constant, the format for evaluating character-string. If you are specifying a range of allowed characters, specify the range in a [a-b] format.
In addition to simple character strings, the following regular expressions can be used in evaluation-format.
-
. (period)
Finds any one character.
-
[] (square brackets)
Finds any single character enclosed in the brackets, or any single character within the range indicated by the characters surrounding a hyphen (-). For example, R[OAI]M finds ROM, RAM, and RIM.
Similarly, S[AE]+D finds SAD, SED, SEED, and SAAD, but does not find SAED or SEAD.
C[0-9] finds C0, C1, C2, and so on.
Specifying a circumflex (^) as the first character in the square brackets negates the meaning, and finds all characters other than the character that follows the circumflex.
-
[^]
Finds any one character that is not the character following the circumflex (^), or is not in the range of characters indicated with the hyphen following the circumflex.
For example, x[^0-9] finds xa, xb, xc, and so on, but does not find x0, x1, x2, or other x-number pairs.
-
^
Finds the beginning of a character string.
-
$ (dollar sign)
Finds the end of a character string.
-
* (asterisk)
Finds zero or more repetitions of the character or regular expression that appears immediately before the asterisk.
For example, ba*c finds bc, bac, baac, baaac, and so on.
-
+ (addition sign)
Finds one or more repetitions of the character or regular expression that appears immediately before the addition sign.
For example, ba+c finds bac, baac, baaac, and so on.
-
\ (backslash)
Finds the single character that directly follows this escape character specification. It disables the meaning of characters that have special meaning in regular expression character strings, such as asterisk (*) and dollar sign ($). In addition, note that the backslash followed by a t finds a tab character.
-
\t
Matches a tab character.
-
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
Normal end |
NODATA |
No character that matches evaluation-format was found. |
ERROR |
— |
Script execution interrupted |
An invalid argument was specified, or an error other than the above occurred. |
Example
- Example 1
-
The following example checks for characters other than alphanumeric characters:
[SET_VALUE] DATA = 'user$1' VAL = $MATCH(DATA,'[^a-zA-Z0-9]') [IF] VAL = '' [THEN] [SET_VALUE] MSG = 'MATCH OK' $ECHO(MSG) [ELSE] [SET_VALUE] MSG = 'MATCH NG ('+VAL+')' $ECHO(MSG) [IF_END]
- Execution result:
-
MATCH NG (4)
- Example 2
-
The following example checks date formats:
[SET_VALUE] DATA = '2015/04/01' VAL = $MATCH(DATA,'^[1-2][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]$') [IF] VAL != '' [THEN] [SET_VALUE] MSG = 'MATCH OK' $ECHO(MSG) [ELSE] [SET_VALUE] MSG = 'MATCH NG' $ECHO(MSG) [IF_END]
- Execution result:
-
MATCH OK