java - Regex to remove everything between two strings but with repetitions -
example string: before text, <ref>{{blahblahblahblah}}</ref> after text, <ref>{{reference2}}</ref> end of paragraph.
i'm looking remove mention of <ref>
, </ref>
, in between.
the result want above example string: before text, after text, end of paragraph.
i have read regex remove between 2 strings , have tried replaceall("<ref>.*</ref>", "")
, problem i'm having method in thread removing much. if use method on above text result : before text, end of paragraph
. cut out text in-between sets of <ref>
tags.
is there easy regex way achieve desired result? in actual text there might many (more 2) sets of <ref>
</ref>
tags useful text in-between.
edit: added regex tried.
if you're going off answer in referenced question you're indeed "removing much" because answer uses greedy operator, use *?
non-greedy match instead ...
i propose following regular expression if must use 1 @ all:
str = str.replaceall("(?s)<ref>.*?</ref>", "");
note: inline (?s)
mode modifier allows dot match across newline sequences.
Comments
Post a Comment