Skip to main content

Tested regular expression does not work

  • March 22, 2011
  • 9 replies
  • 0 views

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca

9 replies

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
The expression you provided does work on Linux using an Acu v9.0 runtime, which supports POSIX-compliant Extended Regular Expressions. However, on Windows, the Acu regular expressions are provided by the CAtlRegExp class. There are definite differences in the syntax supported by these two implementations. In your case, it appears to be the lack of {n} or {n,m} syntax to designate a repeat count or range. It does support the ? operator which designates a zero-or-one repetition. It also supports using \\d as an abbreviation for any decimal digit (same as [0-9], but shorter).

So, you could rewrite your expression as:

\\$\\{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)\\}

to achieve the desired result.

Note that if you need your code to be portable across Windows and POSIX systems, you can determine (at runtime) the level of regex support on the current system, by using the AREGEXP-GET-LEVEL operation of C$REGEX:

call "C$REGEXP" using AREGEXP-GET-LEVEL giving RETURN-VALUE

A RETURN-VALUE of 0 means no regex processing is available; 1 means it's Windows (meaning the CAtlRegExp implementation), and 2 means it's POSIX Extended Regex.

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
Ok, i tested \\$\\{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)\\} but it does not work. Actually the first part \\$\\{[1-9]\\d?\\d?\\d?\\d?\\} works fine, but adding the | operator break it up.

Also, for my needs grouping operators should be used this way \\$\\{([1-9]\\d?\\d?\\d?\\d?|timestamp)\\} and i have some questions about them: reading from some online documentation , i found that for the CAtlRegExp implementation the group operators are {} instead of (). For testing purpose i tried both versions

\\$\\{([1-9]\\d?\\d?\\d?\\d?)\\} and \\$\\{{[1-9]\\d?\\d?\\d?\\d?}\\} with the working part of the expression; then, after having verified a match with AREGEXP-MATCH, i used AREGEXP-NUMGROUPS and AREGEXP-GETMATCH but both of them return 0 as return code.

Which is the correct use of these functions?

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
Ok, i tested \\$\\{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)\\} but it does not work. Actually the first part \\$\\{[1-9]\\d?\\d?\\d?\\d?\\} works fine, but adding the | operator break it up.

Also, for my needs grouping operators should be used this way \\$\\{([1-9]\\d?\\d?\\d?\\d?|timestamp)\\} and i have some questions about them: reading from some online documentation , i found that for the CAtlRegExp implementation the group operators are {} instead of (). For testing purpose i tried both versions

\\$\\{([1-9]\\d?\\d?\\d?\\d?)\\} and \\$\\{{[1-9]\\d?\\d?\\d?\\d?}\\} with the working part of the expression; then, after having verified a match with AREGEXP-MATCH, i used AREGEXP-NUMGROUPS and AREGEXP-GETMATCH but both of them return 0 as return code.

Which is the correct use of these functions?

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
Ok, i tested \\$\\{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)\\} but it does not work. Actually the first part \\$\\{[1-9]\\d?\\d?\\d?\\d?\\} works fine, but adding the | operator break it up.

Also, for my needs grouping operators should be used this way \\$\\{([1-9]\\d?\\d?\\d?\\d?|timestamp)\\} and i have some questions about them: reading from some online documentation , i found that for the CAtlRegExp implementation the group operators are {} instead of (). For testing purpose i tried both versions

\\$\\{([1-9]\\d?\\d?\\d?\\d?)\\} and \\$\\{{[1-9]\\d?\\d?\\d?\\d?}\\} with the working part of the expression; then, after having verified a match with AREGEXP-MATCH, i used AREGEXP-NUMGROUPS and AREGEXP-GETMATCH but both of them return 0 as return code.

Which is the correct use of these functions?

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
I tested
\\$\\{{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)}\\} with this CAtlRegExp tester and found that this is the exact expression that i need, but it doesn't work in AcuCobol.

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
I tested
\\$\\{{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)}\\} with this CAtlRegExp tester and found that this is the exact expression that i need, but it doesn't work in AcuCobol.

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
That's strange because your expression works for me, as do the AREGEXP-NUMGROUPS and AREGEXP-GETMATCH operations to find the count and locations of the substring(s) that match.

I'm testing this on Windows 7 (64-bit) using the extend version 9.0 compiler/runtime.

Some things to look out for:
1. are you storing the expression in a variable? If so, does the size of the variable match the length of your expression?
2. are you null-terminating the expression?

Keep in mind that any trailing spaces in your expression variable become part of the expression, which is probably not what you want - thus the need to null-terminate.

Here's the working-storage definition that I'm using:

       01  test-expression.
           03  filler    pic x(39)
               value     "\\$\\{{([1-9]\\d?\\d?\\d?\\d?)|(timestamp)}\\}".
           03  filler    pic x value x"00".

Also, make sure you don't call the AREGEXP-RELEASE-MATCH too early - i.e. before you've called the AREGEXP-NUMGROUPS and/or AREGEXP-GETMATCH operations, since they need the match-handle before it's released.

Finally, contrary to what the documentation says, in the AREGEXP-GETMATCH operation, the "group" parameter appears to start at 0 instead of 1.

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
Yes i already found that GETMATCH groups starts from 0 and not from 1 and i got it working.
Finally with the configuration that you suggested also the expression works.
Previuosly i was using a level 78 to compile the expression but i also tried to use a level 77 with trailing spaces filled by low-value without succeeding.

Thank you.

[Migrated content. Thread originally posted on 21 March 2011]

Hi, i have this regular expression: \\$\\{([1-9]{1}[0-9]{0,4}|timestamp)\\} that matches with strings like ${1}, ${12345}, ${20} and ${timestamp} and don't with strings like ${a}, ${123456}, ${0}. I tested it with the online tester at here and it works but i can't get it working in the runtime, it compiles but it doesn't match at all.
I also tried some simplified versions like \\$\\{[1-9] [0-9]*\\} that matches for example with ${10} and not with ${0} and this doesn't work as well.
The only iper-simplified version that i got working is \\$\\{[^0] [0-9]*\\}. Obviuosly all this simple versions does not suite my needs, i have to get the first one working.

Can you help me? Does the syntax is correct for acu runtime (9)?

Thank you,
Luca
Yes i already found that GETMATCH groups starts from 0 and not from 1 and i got it working.
Finally with the configuration that you suggested also the expression works.
Previuosly i was using a level 78 to compile the expression but i also tried to use a level 77 with trailing spaces filled by low-value without succeeding.

Thank you.