java - regular expression to find special character & between xml tags -
a xml string generated model pass me, may contains special character such & in text of xml tag.
e.g.
<entry> <key>state</key> <value xsi:type="xs:string">adddress 3 & addr 4, 12345, hong kong</value> </entry> when build xml string have invalid character error, need escape special character &.
want use regex find & between <value></value> tag , replace &
have tried fail on regex.
can give me clue on regex?
besides use java 1.6
you can use lookahead:
replace
&(?!\w*;)(?=[^<]*</value>) by
& this works specifying 2 lookaheads. first lookahead (?!\w*;) prevents valid html escape sequences being matched. second lookahead (?=[^<]*</value>) specifies </value> tag must follow text (after amount of non-xml-tag content).
try here.
Comments
Post a Comment