question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

match with quoted pattern

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
SliverySkycommented, May 8, 2020

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.

0reactions
jhycommented, Jul 15, 2021

Thanks all

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found