[MDEV-20064] regexp_replace + not greedy Created: 2019-07-15  Updated: 2019-07-15  Resolved: 2019-07-15

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0.28
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Dag Nygren Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

fedora fc23 mariadb



 Description   

The expression:

SELECT REGEXP_REPLACE('Season 8, 12/12. ','.*([0-9]+)/[0-9]+.*','\\1');

Should return "12", but now returns "2" (as in ungreedy eval.)



 Comments   
Comment by Dag Nygren [ 2019-07-15 ]

Also tested with a fresher Mariadb 10.2.19 and the same error is still there.

Comment by Sergei Golubchik [ 2019-07-15 ]

For comparison:

$ perl -le '$_="Season 8, 12/12. "; s!.*([0-9]+)/[0-9].*!$1!; print'
2

It is greedy, and the greedy .* eats up as much as it can. If you do it non-greedy regexp, it'd do what you want:

$ perl -le '$_="Season 8, 12/12. "; s!.*?([0-9]+)/[0-9].*!$1!; print'
12

Comment by Dag Nygren [ 2019-07-15 ]

Ahh. You are so right! Was focusing too much on the group. This can be closed. Sorry for the noise!

Generated at Thu Feb 08 08:56:27 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.