EndPointCorp / end-point-blog

End Point Dev blog
https://www.endpointdev.com/blog/
17 stars 65 forks source link

Comments for How to use regular expression group quantifiers in PostgreSQL #1828

Open jonjensen opened 2 years ago

jonjensen commented 2 years ago

Comments for https://www.endpointdev.com/blog/2022/01/regex-group-quantifiers-postgresql/ by Selvakumar Arumugam

To enter a comment:

  1. Log in to GitHub
  2. Leave a comment on this issue.
lveronese commented 2 years ago

This is another possible solution:

WITH f(fields) AS (
  SELECT *  
  FROM regexp_split_to_array('||121212^^^2^ID 1|676767||SELVA^KUMAR^^^^|19480203|M||B||123456 SAMPLE ROAD^^New York City^NY^12345^USA^H^^New York||123456-7890|||M|NON|4000|', '\|')
),
c(component) AS (
  SELECT component
  FROM f, regexp_split_to_array(fields[12], '\^') AS c(component)
)
SELECT component[1] AS address,
       component[2] AS address2,
       component[3] AS city,
       component[4] AS state,
       component[5] AS zip,
       component[6] AS country
FROM c
jonjensen commented 2 years ago

@lveronese Very nice!