Is there a solution in postgres for matching as per below example:
'test' table entries:
id | url
----+-------------------------------------------------------------
1 | /services/system
2 | /services/system/{uuid}/group
3 | /services/system/{uuid}/group/{uuid}/port
I want to match the following input strings against the url column that exist in table:
1. /services/system/1/group --> should match row 3
2. /services/system/1/group/2/port --> should match row 3
3. /services/system/1/group --> should match row 2
4. /services/system/1/group/2 --> should not match
5. /services/system/1 --> should not match
I tried following query to match the match the 3rd row, but it did not work:
select * from test where regexp_replace(url, '{uuid}', '*', 'g') ~ '/services/system/1/group/1/port'
Any solution?
*isn't the wildcard character in a regex. You need to use.+or maybe[0-9]+to only match numbersselect * from test where regexp_replace('/services/system/1/group/1/port', '[0-9]+', '{uuid}', 'g') = url