0

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
  • what have you tried so far? Commented Jul 2, 2018 at 21:01

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.