Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOTALL for String.matches()

Tags:

java

string

regex

I know that DOTALL is available for the fully fledged Pattern+Matcher classes.

But if I want to only use String.matches(), is there a way to tell it to use the DOTALL modifier?

like image 632
ef2011 Avatar asked Oct 27 '11 03:10

ef2011


People also ask

What is pattern Dotall?

DOTALL is a static constant defined in the Pattern class. To enable dotall mode, we create an instance of the Pattern class using the compile() method, and pass the regex and Pattern. DOTALL constant.

What does string matches do in Java?

Java - String matches() Method This method tells whether or not this string matches the given regular expression. An invocation of this method of the form str. matches(regex) yields exactly the same result as the expression Pattern. matches(regex, str).

What is string regex?

Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressions are provided under java.

What is string pattern in Java?

The compile(String) method of the Pattern class in Java is used to create a pattern from the regular expression passed as parameter to method. Whenever you need to match a text against a regular expression pattern more than one time, create a Pattern instance using the Pattern.


1 Answers

You can enable it with the embedded flag (?s), as in

"\n".matches("(?s)."); // true

Here's the Javadoc.

like image 130
Daniel Lubarov Avatar answered Oct 23 '22 17:10

Daniel Lubarov