0

Acceptable format:

0
1,2
1,100,2000,30000
etc...

Regular expression:

Match(a_s_stat, "^\d+(,\d+)*$")

The function returns false. String a_s_stat is: 0,1

How to save correctly a regular expression in PowerBuilder 9.0?

user3064885
  • 1
  • 2
  • 3
  • 1
    Try `"^[0-9]+(,[0-9]+)*$"`. Also, you might be interested in a regex extension, like [BNI PbniRegex](http://stackoverflow.com/questions/487406/looking-for-a-regular-expression-extension). – Wiktor Stribiżew May 24 '16 at 07:30
  • Unfortunately, your proposal does not work. I've tried before in this way. I can not use PBNI PbniRegex - I did not decide about it. – user3064885 May 24 '16 at 11:18
  • [Found it](http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc37783.1250/pdf/dwref.pdf). The parentheses are a culprit! and that means you **cannot use `Match` for your task** because there is no way to define a *group*, a *sequence of characters to quantify*. So, you can only use a simplified "regex" (we call them just *patterns*, not regular expressions) like `^[0-9,]+$`, that will also match `,,,,,,` like strings – Wiktor Stribiżew May 24 '16 at 11:38
  • As an option, try to list as many optional sequences as you can: `[0-9]+,?[0-9]*,?[0-9]*,?[0-9]*,?[0-9]*,?[0-9]*,?[0-9]*,?[0-9]*,?[0-9]*` - but again there can be matches like `12,,,,,,12,,,` – Wiktor Stribiżew May 24 '16 at 11:45

1 Answers1

0

This code should solve your problem - although not as pleasant as a "real" regex

if Match(data, "^[0-9]+$") or &
    ( Match(data, "^[0-9]+[,0-9]*[0-9]+$") and not Match(data, ",,") ) then
    statusText = "<data> is list of integers"
else
    statusText = "Cannot interpret <data> as list of integers"
end if
MicKr-
  • 186
  • 3