CALL "C$REGEXP" USING opCode parameters GIVING returnCode |
opCode | Specifies the operation to perform. Valid values, defined in iscobol.def, are: | |
Tells if regular expressions are supported. | ||
Validates a regular expression. | ||
Applies a regular expression to a string. | ||
Frees memory that is allocated by CREGEXP-MATCH. | ||
Frees memory allocated by CREGEXP-COMPILE. | ||
Returns the number of substrings that matched any subgroups in the regular expression. | ||
Returns a set of indices into a string passed to CREGEXP-MATCH that match the subexpression of the regular expression. | ||
Returns the last error. | ||
parameters | Parameters depend on the opcode. |
working-storage section. copy "iscobol.def". 01 h-regex handle. 01 h-match handle. 01 reg-expr pic x(32). 01 eng-phrase pic x(64) value "Today is a beautiful day". 01 ita-phrase pic x(64) value "Oggi รจ una bella giornata". 01 text-to-parse pic x(64). 01 match-start pic 99. 01 match-end pic 99. 01 err-msg pic x(64). procedure division. main. *check if regexp are supported call "c$regexp" using cregexp-get-level. if return-code = 0 display "regular expressions not supported." stop run end-if. *compile the regexp string "[^\x00-\x7F]+" x"00" into reg-expr. call "c$regexp" using cregexp-compile, reg-expr giving h-regex if h-regex = 0 call "c$regexp" using cregexp-last-error, err-msg display return-code " " err-msg stop run end-if. *test eng-phrase for non-ASCII characters move eng-phrase to text-to-parse. perform check-text. *test ita-phrase for non-ASCII characters move ita-phrase to text-to-parse. perform check-text. *release regexp memory and exit call "c$regexp" using cregexp-release, h-regex. goback. check-text. display "'" function trimr(text-to-parse) "' " no advancing move 0 to match-start. call "c$regexp" using cregexp-match, h-regex, text-to-parse 0, match-start, match-end giving h-match. if h-match = 0 display "doesn't contain non-ASCII characters" else display "contains non-ASCII characters, i.e. '" text-to-parse(match-start:match-end - match-start) "'" end-if. call "c$regexp" using cregexp-release-match, h-match. |