You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both patterns should work, as they match exactly the same strings.
Actual behavior
The second pattern fails to find the DOM element.
Additional context
Java has the Regex special escapes \Q and \E, which means all characters are quoted as is betwen those two escape sequences. This is exactly what Pattern.quote does.
In other words, these are equivalent (as you can see if you print the result of Pattern.quote): Pattern.compile("\\Qsometext\\E") Pattern.compile(Pattern.quote("sometext"))
This is speculation, but why it might fail is if the regex is just transferred to the Javascript engine and executed there. Javascript does not seem to have the \Q and \E special escapes, which leads to the meaning of the passed regex to change.
You can also check here, switch between Java and ECMAScript engines; it works for Java but not for Javascript: https://regex101.com/r/lJ1XNH/1
Environment
macOS Sequoia, arm64
Java 17
Chromium browser (others not tested)
The text was updated successfully, but these errors were encountered:
This is speculation, but why it might fail is if the regex is just transferred to the Javascript engine and executed there. Javascript does not seem to have the \Q and \E special escapes, which leads to the meaning of the passed regex to change.
Yes, this is correct, Playwright shares the implementation between all language ports and it is JavaScript regex syntax that we support.
Version
1.47.0
Steps to reproduce
Using Playwright Java, navigate to https://playwright.dev
Run the following assertions:
working:
not working:
Expected behavior
Both patterns should work, as they match exactly the same strings.
Actual behavior
The second pattern fails to find the DOM element.
Additional context
Java has the Regex special escapes
\Q
and\E
, which means all characters are quoted as is betwen those two escape sequences. This is exactly whatPattern.quote
does.In other words, these are equivalent (as you can see if you print the result of
Pattern.quote
):Pattern.compile("\\Qsometext\\E")
Pattern.compile(Pattern.quote("sometext"))
This is documented here (search for "Quotation"): https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html
This is speculation, but why it might fail is if the regex is just transferred to the Javascript engine and executed there. Javascript does not seem to have the
\Q
and\E
special escapes, which leads to the meaning of the passed regex to change.You can also check here, switch between Java and ECMAScript engines; it works for Java but not for Javascript: https://regex101.com/r/lJ1XNH/1
Environment
macOS Sequoia, arm64
Java 17
Chromium browser (others not tested)
The text was updated successfully, but these errors were encountered: