1. ma jack
  2. PowerBuilder
  3. Thursday, 23 May 2024 12:46 PM UTC

Hi all.
I'm using the match function to match a string that doesn't contain lowercase letters, but I'm getting an error with the following code example

if match("abc", "^.*[^a-z]+.*$") then
    messagebox("", "match")
end if


I checked the documentation Match to confirm that the pattern can be written this way, but why is the result wrong?
I'm using PB2019R3.

Andreas Mykonios Accepted Answer Pending Moderation
  1. Thursday, 23 May 2024 13:09 PM UTC
  2. PowerBuilder
  3. # 1

Hi.

Why you need the dots (.) and the asterisks (*)? An expression like:

if match("abc", "^[^a-z]+$") then
   messagebox("", "Doesn't contains lower case chars")
else
   messagebox("", "Contains lower case chars")
end if

should be enough.

Andreas.

Comment
  1. ma jack
  2. Friday, 24 May 2024 07:31 AM UTC
I wanted to check for non-alphanumeric symbols that appear at least once in the string, and to avoid enumerating all the symbols so I wanted to use "[^A-Za-z0-9]", and the result is what I have now, which doesn't fit the expectation
  1. Helpful
  1. Andreas Mykonios
  2. Friday, 24 May 2024 07:31 AM UTC
You are right about [^a-z]+. You can always open a support ticket for that asking Appeon to improve match function to better handle this situation.

Andreas.
  1. Helpful
  1. ma jack
  2. Friday, 24 May 2024 07:46 AM UTC
Thank you, Andreas.

The enhancement request for the match function has been submitted and is being processed, the next step is to wait :)

https://www.appeon.com/standardsupport/search/view?id=10248
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 23 May 2024 13:34 PM UTC
  2. PowerBuilder
  3. # 2

Andreas is correct.

If you look at the 11th and 13th sample patterns in the Help document URL you referenced in your question, you'll see:

^[^a-z]$    Matches any single character string that is not a lowercase character

which is almost what you want, and:

^[0-9]+$    Matches any string containing only digits.

If you replace the contents inside the square brackets from the 13th sample pattern (0-9) with the contents of the square brackets from the 11th sample pattern (^a-z), you get:

^[^a-z]+$    Matches any string that does not contain a lowercase character

which is what Andreas has recommended.

HTH, John

Comment
  1. ma jack
  2. Friday, 24 May 2024 01:54 AM UTC
Thanks, John.

I'm actually using "^.*[^A-Za-z0-9]+.*$" to check if the string contains symbols other than numbers and letters, for a string like "Ab@12" the match function returns true, for "abc" it should return false, but now it returns true

  1. Helpful
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Friday, 24 May 2024 05:40 AM UTC
  2. PowerBuilder
  3. # 3

It looks like the match function is too "greedy" when matching ".*" and ".+", especially when it is followed by a negative pattern ("[^...]" ). Match ( "abc@", "^.*[@]$" ) matches correctly but match ( "abc@", "^.*[^@]$" ) also returns true when it shouldn't. Match ( "abc@", "^.*[x]$" ) on the other hand correctly returns false. The function just isn't implemented correctly.

Comment
  1. ma jack
  2. Friday, 24 May 2024 05:59 AM UTC
Thank you, Benjamin.

Yes, I also felt that the match function implementation might be a bit problematic, I tested the pattern in another language and the results were as expected.

To match symbols other than alphanumeric I now have the pattern ". *[! @#%&()...] . *", which lists all the symbols
  1. Helpful
  1. Benjamin Gaesslein
  2. Friday, 24 May 2024 07:00 AM UTC
That works, there seems to be no issue with positive match patterns after ".*". It might not always be a viable solution to type in every possible character. A more practical workaround would be using Dan Cooperstock's wrapper for VBScript.RegExp.

https://community.appeon.com/index.php/codeexchange/powerbuilder/329-regular-expression-object#459
  1. Helpful
  1. ma jack
  2. Friday, 24 May 2024 07:20 AM UTC
Thank you, Benjamin.this is very helpful.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.