I have a table with medication_product_amount
column where there are spaces between numbers and characteres like below:
medication_product_amount
1 UN DE 50 ML
20 UN
1 UN DE 600 G
What I want is to remove the single space ONLY between numbers and characters, something like this:
new_medication_product_amount
1UN DE 50ML
20UN
1UN DE 600G
To do this, I am looking for a regular expression to use in the function REGEXP_REPLACE. I tried using the pattern below, indicating to replace the single space after the numbers, but the output remained the same as the input:
select REGEXP_REPLACE(medication_product_amount, '(^[0-9])( )', '1') as new_medication_product_amount
from medications
Can anyone help me come up with the right way to do this? Thanks!
2
Answers
Your regex is a little off. First what yours does.
'(^[0-9])( )', '1')
The problems and correction:
^
.( )
with justResulting Expression/Query: (demo here)
Match "digit space letter", capturing and the digit and letter using
'([0-9]) ([A-Z])'
, then put them back using back references.