match with quoted pattern
See original GitHub issueI was checking how Jsoup handles :matches(regex) and noticed that the parsing code is not quite robust enough. Here’s a plausible example that fails:
final Document doc = Jsoup.parse("<div>1) foo</div>");
System.out.println(doc.select("div:matches(" + Pattern.quote("1)") + ")"));
This is because Pattern.quote doesn’t escape with backslashes like Jsoup expects, but rather wraps the text between \Q and \E, with some special handling if the original text contained \E.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How can I match a quote-delimited string with a regex?
Check out perldoc.perl.org/perlre.html under "Extended Patterns" (about 1/3 of the way down). In this case, it is just like (stuff) except there is...
Read more >Regex Pattern: Match outer single & double quote pairs
Regex Pattern: Match outer single & double quote pairs. Here are a couple regular expressions for matching quote pairs in a string.
Read more >Regex for Quoted String with escapable quotes - Metal Toad
Regex for Quoted String with escapable quotes · 1. Match a single or double quote, as long as it's not preceded by \...
Read more >Regular Expressions
Regular expressions are patterns that can be matched against strings. ... where the quoted string cannot contain any embedded double quotes; the pattern...
Read more >Understanding the Pattern.quote Method - Baeldung
In this quick tutorial, let's see how we can escape metacharacters inside regular expressions both manually and using the Pattern.quote() method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The bug is that chompBalance() did not ignore the bracket in \Q \E and leads to unbalanced brackets error . It should ignore. So I modify the chompBalance() by ignoring the brackets which are between \Q \E. Then it work well. And I have committed a pull request.
Thanks all