I am trying to create regexp to validate comma separated name value pairs which starts from ID like so
select
'ID,2190,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def,abc,def'
regexp
'^ID,[1-9][0-9]*(,[^,]+,[^,]*)*$'
the above query will output 0 istead of 1, but if i reduce a pair ,abc,def
this will reduce number of commas and the query will output 1
I have tried changing server, on a shared server the query runs fine irrespective of number of values
Can anyone tell me, is my query failing because of server configuration or something wrong in my regexp pattern, here i am trying to repeat a capture group 0 to infinite times
2
Answers
The solution was to use non-capturing group
(?:)
instead of capturing group()
the comment from Andy was useful with regex101 link where in description it states you should use non-capturing group when the data is not important
The second part checks whether there are an even number of commas in
col
. (Change0
to1
if you need an odd number.)This formulation probably achieves your goal faster and avoids any regexp size limitation.