0

I have a table like this:

// routes
+----+-----------------------------+
| id |           route             |
+----+-----------------------------+
| 1  | /tracking_code/expire/{id}  |
| 2  | /tracking_code/list         |
+----+-----------------------------+

{} means a dynamic value. And I need to match the first row for this entry value: /tracking_code/expire/2. I guess I need to use regexp. Any idea how can I do that?


My current workaround is using LIKE clause like this:

SELECT * FROM routes WHERE route LIKE :entry%

Also I should remove that number of the end of entry like /tracking_code/expire/.

Sadly my approach won't work for complicated routes like this: /tracking_code/expire/{id}/temp. Anyway, how should I use regexp for this?

stack
  • 10,280
  • 19
  • 65
  • 117
  • Is all the route have the same format, i mean start with `/tracking_code/expire/` followed by a number or what there are other format? – Youcef LAIDANI Dec 09 '17 at 09:20
  • You can't pass `/tracking_code/expire/2` barely into a magical function which takes a route without any delimiters like `/tracking_code/expire/{2}`. If you do this anyway you'll encounter conflicts and costs. – revo Dec 09 '17 at 09:27

1 Answers1

0

You can use RLIKE like this

SELECT * FROM routes WHERE route RLIKE '^.*[0-9]+.*$'

to replace using regex i don't think this is possible, but there are some sneaky way, read this post here How to do a regular expression replace in MySQL?

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140