79680536

Date: 2025-06-26 13:00:54
Score: 1
Natty:
Report link

Does java.util.regex.Pattern, java.util.pattern.Matcher have some "verbatim" mode?

No, Patterns in Java do not have a verbatim or "literal mode" like some other languages. But Java provides an official way to achieve the same effect: using the Pattern.LITERAL flag.

Try to use Pattern.LITERAL:


Pattern pattern = Pattern.compile("\\", Pattern.LITERAL);

Matcher matcher = pattern.matcher("\\");

boolean hasMatch = matcher.find();

assertTrue(hasMatch);

assertEquals("\\", matcher.group());

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Hien Nguyen Thi