java - How to use regex contains " with Pattern.compile -
i have regex :
url\(\s*(['"]?+)(.*?)\1\s*\)
which retrieves url css file .
i utilize code , error :
pattern p = pattern.compile("url\(\s*(['\"]?+)(.*?)\1\s*\)"); matcher m = p.matcher(csstext); while (m.find()) { println m.group() }
as can note add together \
esacpe "
. in vain
you need utilize \\
instead of \
in java regex:
pattern p = pattern.compile( "url\\(\\s*(['\"]?+)(.*?)\\1\\s*\\)" );
1st \
escaping string object 2nd \
escaping underlying regex engine java regex
No comments:
Post a Comment