0

regular expression replace in string ignoring first and last characters if they matched

my try

SELECT REGEXP_REPLACE ('TLYU TK0T23T', '[^(\A.)]T[^(.\Z)]', 'Qq' ) contain FROM dual;    

result

TLYUQqQq3T

expected result

TLYU QqK0Qq23T

Thanks in advance

1 Answer 1

1

This returns the answer you want:

SELECT REGEXP_REPLACE 
('TLYU TK0T23T', '([^(\A.)])T([^(.\Z)])', '\1Qq\2' ) contain 
FROM dual;

Bobby

1
  • You needed to add parentheses around the strings that came before and after the letter T that you were matching. Then in the replace string you refer to the things in parentheses with \1 and \2. I think that the parentheses within the square brackets are not used for this purpose. So, ([^(\A.)]) is \1 and ([^(.\Z)]) is \2. Is that clear? Commented Jul 18, 2018 at 15:46

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.