Products | Versions |
---|---|
ibi WebFOCUS | 8207.27.0 |
The REGEX function matches a string to a regular expression and returns true (1) if it matches and false (0) if it does not match.
Regular expression are enclosed in single quotation marks and constructed using literals and metacharacters. The following metacharacters are supported (.*+?^$[][^|\()]).
How can we use the above mentioned metacharacters as regular strings, disregarding their functionality in a regex function?
The following request matches the FIRSTNAME field against the regular expression '^Sara(h?)$', which matches Sara or Sarah:
TABLE FILE WF_RETAIL_LITE
PRINT FIRSTNAME AND COMPUTE
REG1/I1=REGEX(FIRSTNAME,'^Sara(h?)$') ;
BY LASTNAME/A10
WHERE LASTNAME EQ 'Allen'
END
If you want to use (.*+?^$[][^|\()]) this metacharacters as a string without their functionality, it should be enclosed with in square brackets.
For example: -SET ®1 ='[~`!@#$%¬^&*+={}¢\Ý\¨\|\;:"<>?/\(\)\\]';
Using Regular Expressions on z/OS -
On z/OS, depending on the code page you are using, some of the meta-characters used to create a regular expression may not be interpreted correctly when inserted directly from a Windows keyboard.
If you are using the Unicode code page 65002, the meta-characters will be interpreted correctly. In this environment, you need to be sure the files you are referencing, such as FOCUS data sources, have been built using this code page. If you are not using a Unicode code page, you can use the CHAR function to return the correct meta-characters, based on the decimal code for the EBCDIC character. For example, to insert:
The circumflex (^) meta-character, use CHAR(95).
The left bracket ([) meta-character, use CHAR(173).
The right bracket (]) meta-character, use CHAR(189).
The left brace ({) meta-character, use CHAR(192).
The right brace (}) meta-character, use CHAR(208).
For example, to generate the regular expression '[~`!@#$%¬^&*+={}¢\Ý\¨\|\;:"<>?/\(\)\\]', which matches all metacharacters, issue a -SET command similar to the following, which creates a variable named ®1:
-SET ®1=CHAR(173) || '~`!@#$%¬^&*+={}¢\Ý\¨\|\;:"<>?/\(\)\\' || CHAR(189);
Then use the &VCWSTRING variable as the regular expression argument in the function call. For example:
REG1/I1=REGEX(PRODUCT, '®1');