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

asked Jul 18, 2018 at 14:24

1 Answer 1

1

This returns the answer you want:

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

Bobby

answered Jul 18, 2018 at 15:05
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.