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
Eysawy MohamedEysawy Mohamed
asked Jul 18, 2018 at 14:24
1 Answer 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
-
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?Bobby Durrett– Bobby Durrett2018年07月18日 15:46:29 +00:00Commented Jul 18, 2018 at 15:46
lang-sql