Java regex escaping issue with ampersand
I have a test URL which contains an ampersand in escaped form:
'&'
Then I have the following code:
Pattern urlRegexPattern = Pattern.compile("url\\s*\\(\\s*(['\"]?)(\\S*?)\\1\\s*\\)", Pattern.CASE_INSENSITIVE);
Matcher matcher = urlRegexPattern.matcher(styleContent);
while (matcher.find()) {
String url = matcher.group(2);
....
}
The issue is that the matched url in the loop above contains an ampersand in escaped form (simply &). It seems that the matcher does it automatically, but I’d like to get the matched url exactly as it is without escaping, is it possible? thanks.
Read more here: Source link
