My goal is to delete all matches from an input using a regular expression with Java 7:
input.replaceAll([regex], "");
Given this example input
with a target string abc-
:
<TAG>test-test-abc-abc-test-abc-test-</TAG>test-abc-test-abc-<TAG>test-abc-test-abc-abc-</TAG>
What regex could I use in the code above to match abc-
only when it is between the <TAG>
and </TAG>
delimiters? Here is the desired matching behaviour, with <-->
for a match:
<--><--> <--> <--> <--><-->
<TAG>test-test-abc-abc-test-abc-test-</TAG>test-abc-test-abc-<TAG>test-abc-test-abc-abc-</TAG>
Expected result:
<TAG>test-test-test-test-</TAG>test-abc-test-abc-<TAG>test-test-</TAG>
The left and right delimiters are always different. I am not particularly looking for a recursive solution (nested delimiters).
I think this might be doable with lookaheads and/or lookbehinds but I didn't get anywhere with them.
question from:
https://stackoverflow.com/questions/65907832/how-to-match-a-string-with-a-regex-only-if-its-between-two-delimiters 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…