Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression 1

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Does anybody know the pattern to escape special characters if they arent already escaped?

for example, to escape TEST1&TEST2 but not TEST1 & TEST2

Thanks
 
try this
Code:
String stuff = "&&&&";
stuff = java.util.regex.Pattern.compile("&(?!amp;)", java.util.regex.Pattern.CASE_INSENSITIVE).matcher(stuff).replaceAll("&");
 
Thanks a ton, so this stating any occurence of & followed by the NOT of 1 occurence of amp; (case insensitive) ?

Thanks so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top