I have a string X-99-XX-999 in postgres 9.6. I'm looking to extract XX. The XX is always between the second and the third hyphen. Can anyone please help?
1 Answer
Use the function split_part()
select split_part('X-99-XX-999', '-', 3)
split_part
------------
XX
(1 row)
From the documentation:
split_part(string text, delimiter text, field int)
Split string on delimiter and return the given field (counting from one)