Hi Tom
I have a query that I am trying to replace non white space characters in a given string that may have whole numbers or decimals with a single space (where non spaces are there , examples are below) and there are possible strings that have multiple or one whitespace( the one whitespace doesn't have to be replaced)
Strings that does not have whitespace a single space needs to be inserted also the ones inside the brackets as well for e.g below (can be a combination of whole numbers, decimals and whole string in a single column)
E.g:-
80.0 LBS(50KG) should be 80.0 LBS (50 KG)
102mm Dia) should be 102 mm Dia with the ) removed (typo issue)
610mm should be 610 mm
<= 356mm/14in should be <= 14 Inch(356 mm)
I tried the following but it does not work
SELECT Value as DisplayValue,
CASE WHEN (TRIM(Value) IS NOT NULL AND
REGEXP_LIKE(Value,'[(|[][:space:]*[a-zA-Z.-;,=0-9[:space:]]*\s*(\s*MM|IN|IPM|KG|M|LB|EA|FT|DEG|N|FPM|S|LBS\s*)\s*[:space:]*[]|)]','i'))
THEN REGEXP_REPLACE(EPE.DISPLAYVALUE, '([0-9](MM|IN|IPM|KG|M|LB|EA|FT|DEG|N|FPM|S|LBS)*[-/]\s*[0-9]*[.0-9]*\s*(MM|IN|IPM|KG|M|LB|EA|FT|DEG|N|FPM|S|LBS))','\1 \2') -- for whitespace sinhMM|IN|IPM|KG|M|LB|EA|FT|DEG|N|FPM|S Square Brackets
FROM Table;
Also I have another question, Is it possible to replace as for the following example above <= 356mm/14in to <= 14 Inch (356 mm) (I capital letters in "Inch") with single whitespace and the spaces inside the brackets the format output ?
It sounds like you're trying to fix data entry errors using regular expressions. This is always shaky ground, as the risk of false positives and negatives is high. Trying to fix everything with one giant regular expression is a sure way to madness.
Sure, you could do the replacement with something like:
select regexp_replace (
'356mm/14in',
'([0-9]+)mm.([0-9]+)in',
'\2 Inch (\1 mm)'
) regex
from dual;
REGEX
14 Inch (356 mm)
But you risk this either being:
- Too specific, so you need to write more regexes to handle other mismatches
- Too broad, so it accidentally changes values which happen to match
Ultimately you're going to have to spend a lot of time double-checking the changes; at some point it's quicker just to change the data manually!