php - Mysql REGEX occurence and extraction in string -
i have table my_tbl varchar field my_fld. need find rows my_fld contains number followed hyphen followed number (typically range).
the following lines should selected:
fffff 1-5 fdsfdsfds 1-5 fdsfdsfds aaaa 10-23 1-50 fdsfdsfds and these should not:
-5 dsgdgf 10- rere -15 10 -23 10- 23 the regex number-hyphen-number pattern \d+\-\d+.
how use in mysql statement? possible extract pattern separate string?
fffff 1-5 fdsfdsfds -> 1-5 1-5 fdsfdsfds -> 1-5 aaaa 10-23 -> 10-23 1-50 fdsfdsfds -> 1-50
you may use retrieve matching rows:
select * my_tbl my_fld regexp '[0-9]+-[0-9]+' no need escape - , match digit, use [0-9] bracket expression.
there no easy, built-in way extract regex matches in mysql though.
Comments
Post a Comment