2

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!

Tenzi
  • 101
  • 1
  • 6
  • 12
  • But your regular expression only fulfill the first requirement, doesn't it? You could easily write a function to validate that, second one, much more difficult, but then so it would be with regular expression, unless you use a dictionary, how do you validate groups of words? If you are interested only in the first one, I'll answer with a simple function. – pedromarce Oct 23 '13 at 12:51

4 Answers4

3

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.
Abe Voelker
  • 30,124
  • 14
  • 81
  • 98
  • 5
    Regular expressions are way tooooo futuristic for ABL. – Lieven Cardoen Nov 15 '13 at 07:57
  • @LievenCardoen Damn 11 gold badges? That's sick! – Abe Voelker Nov 15 '13 at 16:08
  • I found it, apparently it's because I ask a ton of questions, which rather makes me stupid than anything else... Famous question (gold medal) : Asked a question with 10,000 views. This badge can be awarded multiple times. I'll sell my gold badges to the highest bidding. – Lieven Cardoen Nov 16 '13 at 09:49
2

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.

Community
  • 1
  • 1
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
0

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").
pedromarce
  • 5,651
  • 2
  • 27
  • 27
0

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.

Gabriel Hautclocq
  • 3,230
  • 2
  • 26
  • 31
  • I'd like to use this but i keep getting this error: "unknown fields or variable name - DLL-CALL-TYPE.201" – kuhle Nov 13 '19 at 07:45
  • @kuhle Is your server a HP-UX 11.31 IA64 or a Linux? If Linux, you have to provide your own lib/libpcre.so because the one I provide is compiled for the HP-UX 11.31 Itanium 64 platform. If you want to use it on Windows, it should work, but maybe you have to compile the pcre3 DLL yourself. – Gabriel Hautclocq Nov 14 '19 at 11:28