Question

I want to check if a variable is in pascal case, in OpenEdge.

I found the matches operator, and I write the following code:

define variable cVariable as character no-undo.

cVariable = "cPascalCase":U.

message cVariable matches 'c[A-Z]*':U.

But it doesn't work, it shows "no". Is there a way to specify in OpenEdge that the second character should be upper case? And more, to check if the variable contains groups of words starting with upper case?

Thanks in advance!

Was it helpful?

Solution

MATCHES does not support regular expressions. The documentation says it only takes simple wildcards like . and *. If you know your code will always run on Windows, you can use the CLR bridge to run .NET code:

USING System.Text.RegularExpressions.*.

DEF VAR cVariable AS CHAR NO-UNDO INITIAL "cPascalCase".
DEF VAR regexp AS CLASS Regex NO-UNDO.

regexp = NEW Regex("c[A-Z]*").
MESSAGE regexp:IsMatch(cVariable).

FINALLY:
  DELETE OBJECT regexp.
END.

OTHER TIPS

Progress does not directly support regular expressions.

For some examples of using regular expressions: using System.Text.RegularExpressions within OpenEdge ABL

Progress variables are not case sensitive. To work with a case sensitive string you can declare a variable to be case-sensitive like so:

define variable s as character no-undo case-sensitive.

display "aBc" matches "abc".

s = "aBc".

display s matches "abc".

display s matches "a*c".

Or you can use the UPPER() and LOWER(), ASC() and CHR() functions to make character by character comparisons.

You can't use regular expressions with Progress unless you use .NET classes, but your requirement is easily implemented with a simple function.

FUNCTION isPascalCase RETURNS LOGICAL
    (cString AS CHARACTER):

  IF LENGTH(cString) < 2 THEN 
      RETURN FALSE.

  RETURN SUBSTRING(cString,1,1) = "c" AND 
           ASC(SUBSTRING(cString,2,1)) = ASC(UPPER(SUBSTRING(cString,2,1))).


END FUNCTION.

MESSAGE isPascalCase("cpascalCase").

You can use a class that I developed. It's available in https://github.com/gabsoftware/Progress-ABL-4GL-Regex. This class adds support for Perl regular expressions for Windows and HP-UX 11.31 ia64.

It's very easy to use. Just do the following:

DEFINE VARIABLE cl_regex   AS CLASS Regex NO-UNDO.
DEFINE VARIABLE ch_pattern AS CHARACTER   NO-UNDO CASE-SENSITIVE.

ASSIGN
    ch_pattern = "c[A-Z]*"
    cl_regex   = NEW Regex().

/* should display: "No" */
MESSAGE cl_regex:mMatch( "ctest", ch_pattern, "" )
VIEW-AS ALERT-BOX.

Note that you have to escape Progress special characters in your pattern, as described here: http://knowledgebase.progress.com/articles/Article/P27229 or it will not work as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top