I have a database of addresses where acronyms have been separated with a space, I want to remove these space so I turned to trusty regular expressions. However, I am struggling to perform a secondary function on the regexp result '\&' - I have checked the forums and docs and just cannot get this to work. Example data I have is as follows:
- 'A V C Welding' should be 'AVC Welding'
- 'H S B C' should be 'HSBC'
- etc..
I have the following regexp:
trim(regexp_replace(organisation || ' ', '(([A-Z]\s){1}){2,}', replace('\&',' ',''), 'g'))
The replace('\&',' ','') is not having any effect at all, I just get the same string back. I have tried other functions e.g. lower('\&') and none of these seem to work as expected. Concatenation with || does work however. I have tried casting the '\&' to text, tried replace('' || '\&' || '',' ','') - still, no joy.
Any advice would be much appreciated, I am sure the solution is something very simple but I just cannot see where to go next!
select trim(regexp_replace('A V C Welding', '(([A-Z]\s){1}){2,}', replace('\&',' ',''), 'g'));returnsA V C Weldingwhereas I am expectingAVC Weldingreplace('\&', ' ', '')? It's a certain no-op this way.'\&contains the matching text for the regexp that I would just be able to replace the spaces in this and get what I need e.g. turn 'A V C Welding' into 'AVC Welding'. If I use a fixed string instead of a function it works e.g.select trim(regexp_replace('A V C Welding', '(([A-Z]\s){1}){2,}', 'XXX ', 'g'));returns 'XXX Welding' so I don't think I am that far off.