Title: Using Regular Expressions to replace text in your program

Regular expressions can be used to replace text in your programs without changing your code. You do this by setting iscobol.compiler.regexp and compiling your code. The format is:

    iscobol.compiler.regexp=<existing-value> <new-value> <existing-value> <new-value> ...
Some common regular expression characters we use are:
+------+-------------------------------------------+------------------------------------------------+
| (?i) | Makes the following text case insensitive | (?i)STOP will catch "Stop", "STOP", and "stop" |
+------+-------------------------------------------+------------------------------------------------+
| \\s+ | Space or spaces                           | Indicates one or more spaces in the text       |
+------+-------------------------------------------+------------------------------------------------+
| .    | Period	                                   | Replaces one character                         |
+------+-------------------------------------------+------------------------------------------------+

Examples:

Comment out a line

    iscobol.compiler.regexp=" RECORD" " * RECORD"
    iscobol.compiler.regexp="RECORDING MODE" "*> RECORDING MODE"

Replace all 'STOP RUN's with 'GOBACK', ignoring letter case and spacing
    iscobol.compiler.regexp="(?i)(STOP)\\s+(RUN)" "GOBACK"

Change the name of copybooks
    iscobol.compiler.regexp="acugui.def" "isgui.def" "acucobol.def" "iscobol.def" 
Another way to do this and make it more readable is to use the line extension backslash:
    iscobol.compiler.regexp="acugui.def" "isgui.def" \
                            "acucobol.def" "iscobol.def" \
                            "crtvars.def" "iscrt.def"

Replace text with spaces
A program that uses the special names "call-convention" would need to remove this line, since isCOBOL uses a configuration variable instead.
So this regular expression replaces "call-convention is dynmaicStdCall" and "call-convention is WINAPI" with spaces.

    iscobol.compiler.regexp="(?i)(dynamicStdCall)" " " \
                            "(?i)(call-convention)\\s+(66)\\s+(is)" " " \
                            "(?i)(WINAPI)" " " \
                            "(?i)(call-convention)\\s+(74)\\s+(is)" " "
Notes: - You can only specify this configuration variable one time, passing it a string of all of the regular expressions you need. If you set it twice, the second one will overwrite the first one. This can get a bit long but remember that you can use the line continuation backslash "\" at the end of a line. - This is a compiler configuration - it requires you to compile or recompile with it set.

Authored by: Veryant Support on Tue, Aug 28th, 2018 at 7:00 PM
This question has been viewed 222 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=295

Powered by PHPKB Knowledge Base Software