regex java: how to replace a string in a generic between the start tag and end tag of a generic -
in java, have string so:
"bla bla bla bla [back] bla bla bla [bla bla [go] bla bla bla bla [bla"
and want find rule regex replace start tag "[" "(start)" , end tag "]" "(end)".
a "start-tag or end tag alone" should ignored.
the result following:
bla bla bla bla (start)back(end) bla bla bla [ bla bla (start)go(end) bla bla bla bla [bla
string resultstring = subjectstring.replaceall( "(?x) # turn on verbose mode \n" + "\\[ # match [ \n" + "( # match , capture in group 1: \n" + "[^\\[\\]]* # number of characters except brackets\n" + ") # end of capturing group \n" + "\\] # match ]", "(start)$1(end)");
will match/replace balanced [
/]
pairs no brackets in-between them.
Comments
Post a Comment