简体   繁体   中英

psql search specific word

I am looking for the following expression specifically but I do not obtain it

I've tried the following

SELECT regexp_replace('KR 733 asd 12 12 NO SUR', '([^0-9]+)', ' ', 'g') || regexp_replace('KR 733 asd 12 12 NO SUR', '[^(SUR|ESTE)]', ' ', 'g')

the result it is

" 733 12 12  R                  SUR"

But I need it is Only three number and the words (SUR|ESTE)

" 733 12 12 SUR"

Another case

"CL 23 AS 343A 34 ESTE" => "23 343 34 ESTE"

"CL 23 AS 343A 34 50 30 ESTE" => "23 343 34 ESTE"

Try to use this regex

SELECT regexp_replace('KR 733 asd 12 12 NO SUR', '([a-zA-Z]+)[^(?:\d|SUR|ESTE)]', ' ', 'g')

But it will keep any numbers presented in the string with SUR or ESTE at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM