MATCH_REG function
Function
MATCH_REG{PATTERN, MATCH_STRING,NOMATCH_STRING}
When a mapped character string matches the condition specified in PATTERN, this function converts the character string to a value specified in MATCH_STRING. If there is no match, the character string is converted to a value specified in NOMATCH_STRING. This function can be used to determine the validity of a value.
You can use regular expressions in the arguments. For details about typical meta characters that can be used as regular expressions, see Table A.11 Regular expressions that can be used with the REPLACE_REG function. However, note that the MATCH_REG function does not support back reference.
-
If the encoding of the input data is EBCDIC or JIS, external characters cannot be used because replacement is performed after changing the encoding to UTF-8.
The encoding is first changed to UTF-8 even when nothing matches with PATTERN (character string to be searched for), or also when hexadecimal notation is used for PATTERN (character string to be searched for). Operations are not guaranteed if you use any platform-dependent characters.
-
For behavior specifications related to encoding differences in the input data, see Behavior specifications related to encoding differences in the input data
Parameters
PATTERN
Specify the match condition. (This parameter cannot be omitted.)
MATCH_STRING
Specify the character string that the mapped character string should be converted into if it matched the condition specified in PATTERN. (This parameter cannot be omitted.)
NOMATCH_STRING
Specify the character string that the mapped character string should be converted into if it does not match the condition specified in PATTERN. (This parameter cannot be omitted.)
Example
Character strings that include あ are converted to ○, and those that do not include あ are converted to ×.

Figure A.20 Example of using the MATCH_REG function
For an example that uses a regular expression for an argument, see Example of using the MATCH_REG function.
Behavior specifications related to encoding differences in the input data
When the encoding of the input data is EBCDIC type or JIS
The description of this section is based on the case shown below. The following data is expressed in hexadecimal.
Kanji code type in the input settings |
JEF |
EBCDIC set in the input settings |
EBCDIC kana |
Kanji code type in the output settings |
JEF |
EBCDIC set in the output settings |
EBCDIC kana |
Input data |
40 20 40 9C 01 20 10 9C |
Field type of the input data |
X(character) |
Function |
MATCH_REG{\x20\x10\x20,ABC,UNMATCH} |
1) Before MATCH_REG is executed, the input character string is converted to UTF-8.

Figure A.21 Converting to UTF-8
"0x40" (space) and "0x9C" (code that is unable to be converted to UTF-8) are converted to "0x20".
2) MATCH_REG is executed on the data converted to UTF-8.

Figure A.22 Executing MATCH_REG
"20 10 20" matches the condition, so the converted data is replaced with "41 42 43" (character string "ABC" in UTF-8).
3) The result data of MATCH_REG is converted to the JEF/EBCDIC set based on the output settings.

Figure A.23 Converting to the JEF/EBCDIC set based on the output settings
"41 42 43" (character string "ABC" in UTF-8) is converted to "C1 C2 C3" (character string "ABC" in EBCDIC).
When the encoding of the input data is SHIFT-JIS, EUC, UTF-16, or UTF-8
The description of this section is based on the case shown below. The following data is expressed in hexadecimal.
Kanji code type in the input settings |
EUC |
Kanji code type in the output settings |
SHIFT-JIS |
Input data |
40 20 40 9C 01 20 10 9C |
Field type of the input data |
M (variable-length characters) |
Function |
MATCH_REG{\x20\x10\x9C,あいう,UNMATCH} |
1) MATCH_REG is executed on the input data.

Figure A.24 Executing MATCH_REG
"20 10 9C" matches the condition, so the input data is replaced with "E3 81 82 E3 81 84 E3 81 86" (character string "あいう" in UTF-8).
2) The UTF-8 data replaced using MATCH_REG is converted to SHIFT-JIS based on the output settings.

Figure A.25 Converting to SHIFT-JIS based on the output settings
"E3 81 82 E3 81 84 E3 81 86" (character string "あいう" in UTF-8) is converted to "82 A0 82 A2 82 A4" (character string "あいう" in SHIFT-JIS).