1

I want to repair some data, which was uploaded using incorrect encoding. Consider the following example:

RUE DE SAN MARTI¦O N¦ 123

I want to replace the ¦ with say #, but only in cases when it's preceeded by a number or the character N

My desired output is:

RUE DE SAN MARTI¦O N# 123

I tried the following replace:

SELECT REGEXP_REPLACE('RUE DE SAN MARTI¦O N¦ 123','[\d]\¦|[N]\¦','#')
  FROM dual;

which correctly detects the chacter to match, but from what I know replacement string is used as literal. However I want to preserve the N before ¦. Has anyone had any luck solving similar issue?

1 Answer 1

2

You may use

([0-9N])¦

and replace with \1#.

See the regex demo

Details:

  • ([0-9N]) - a capturing group matching a digit or N (can be referred to with the \1 backreference from the replacement pattern)
  • ¦ - a literal symbol is matched.

See an Oracle online demo:

SELECT REGEXP_REPLACE('RUE DE SAN MARTI¦O N¦ 123','([0-9N])¦','\1#') AS Result FROM dual

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Regular expressions have never been my forte, thank you very much. It worked as a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.