EN VI

Regex - Postgres find string starting with specific characters?

2024-03-14 19:30:04
How to Regex - Postgres find string starting with specific characters

I have this table, in which the order_name was randomly typed. I want to extract the order code after 437. for 22 characters in their original format, e.g. 437.8/03-87 22LA190028 (it was wrongly written in the second record).

id order_name
1 First order 437.8/03-87 22LA190028
2 Second order 437.8-03-87 22LA190028
3 First order 437.3/10-87 16NY100013 - Return
4 Order 21.02.2022 437.8/10-87 16WA239766
5 437.8/10-87 16NY100234 - Paid
6 First order (437.8/03-87 22LA190028)
7 Visit 02.02.2023 Order 437.5/10-87 16DC107765

I will really appreciate your help.

Solution:

If the string you want ALWAYS starts with 437 and has a length of 22 you can use the following regex statement:

437...................

I think you can select the result of this in postgres by:

SELECT REGEXP_MATCHES(order_name,#'437...................')
FROM yourtable
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login