java - Making group constraints in Regex in android -
so have string:
string articlecontent = "dfgh{jdf%g{%qf234ad%22!#$56a%}vzsams{%3%45%}678456{78";
i want remove between {% %}
so result :
dfgh{jdf%gvzsams678456{78
i tried this:
string regex = "[{%][^[%}]&&\\p{graph}]*[%}]"; string abc = articlecontent.replaceall(regex, "");
but is:
dfghfgqf234ad}vzsams3}678456{78
what suppose i'm doing wrong not able make group of "{%" instead of [{%] or condition { or % .
any suggestions?
edit 1: string have taken example. can have special characters in between {% , %} not ! , %
you can pattern:
string regex = "\\{%(?>[^%]++|%(?!}))*%}";
explanations:
the goal of pattern reduce @ minimum number of backtracks:
\\{% # { need escaped (?> # open atomic group * [^%]++ # characters %, 1 or more times (possessive *) | # or %(?!}) # % not followed } (<-no need escape) )* # close atomic group, repeat 0 or more times %}
(* more informations possessive quantifiers , atomic groups)
Comments
Post a Comment