support: Customer Portal
Focused on delivering choice, investment protection and flexibility to organizations with valuable COBOL assets
 

Veryant Knowledge Base
Home > All Categories > Compiler General > Using Regular Expressions to replace text in your program
Question 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 This question has been viewed 63 times so far.
Click Here to View all the questions in Compiler General category.
File Attachments File Attachments
How helpful was this article to you?
User Comments User Comments Add Comment
There are no user comments for this question. Be the first to post a comment. Click Here
Related Questions Related Questions
  1. Why do I get the error "java.lang.NoClassDefFoundError: com/sun/tools/javac/Main" ?
  2. How do I resolve "Error writing file: too many constants" error?
  3. What compiler options cannot be specified with the >> IMP OPTION compiler directive?
  4. Is there a faster way to compile?
  5. How can I make my Linkage parameters more flexible?
  6. How do I retrieve the version of the Java Compiler and the isCOBOL Compiler that produced a given class file?
Article Information Additional Information
Article Number: 295
Created: 2018-08-28 9:25 AM
Rating: No Rating
 
Article Options Article Options
Print Question Print this Question
Email Question Email Question to Friend
Export to Adobe PDF Export to PDF File
Export to MS Word Export to MS Word
Bookmark Article
Subscribe to Article Subscribe to Article
 
Search Knowledge Base Search Knowledge Base



 
 

© Veryant - All Rights Reserved
Veryant and isCOBOL are trademarks or registered marks of Veryant in the United States and other countries. All other marks are the property of their respective owners.