It’s because you are trying to match against the entire string instead of the part to find. For example, this code will find that only a part of the string is conforming to the present regex:
Matcher m = Pattern.compile("he|be|de").matcher("he is "); m.find(); //true
When you want to match an entire string and check if that string contains he|be|de use this regex .*(he|be|de).*
.
means any symbol, *
is previous symbol may be present zero or more times. Example:
"he is ".matches(".*(he|be|de).*"); //true
Related Posts:
- How to match “any character” in regular expression?
- Understanding regex in Java: split(“\t”) vs split(“\\t”) – when do they both work, and when should they be used
- How to match “any character” in regular expression?
- How to replace ” \ ” with ” \\ ” in java
- What does regular expression \\s*,\\s* do?
- How can I remove punctuation from input text in Java?
- Java; String replace (using regular expressions)?
- How can I remove punctuation from input text in Java?
- Range of valid character for a base 64 encoding
- List of all special characters that need to be escaped in a regex
- Regular Expressions on Punctuation
- How to extract a substring using regex
- Whitespace Matching Regex – Java
- How to represent a fix number of repeats in regular expression?
- Using regex to match any character except =
- How to use regex in String.contains() method in Java
- Whitespace Matching Regex – Java
- Difference between regex [A-z] and [a-zA-Z]
- Regex pattern including all special characters
- Use String.split() with multiple delimiters
- Split string into array of character strings
- Java regex email
- How can I convert a char to int in Java? [duplicate]
- “PKIX path building failed” and “unable to find valid certification path to requested target”
- How can I convert IPV6 address to IPV4 address?
- Spring Boot – Unable to resolve Whitelabel Error Page
- When do you use Java’s @Override annotation and why?
- Java Error “Exception in thread “main” java.util.InputMismatchException” On an Array program
- When is the @JsonProperty property used and what is it used for?
- Print ArrayList
- “Missing return statement” within if / for / while
- Make copy of an array
- How can I use ant
to execute commands on linux? - Invalid initial heap size -Xms4096M
- How do I use a PriorityQueue?
- What does Java option -Xmx stand for?
- Illegal Escape Character “\”
- Error – trustAnchors parameter must be non-empty
- Searching for UUIDs in text with regex
- Calculating the angle between the line defined by two points
- Wait for page load in Selenium
- Constructor cannot be applied to given types?
- Printing HashMap In Java
- Java “.class expected”
- Java Initialize an int array in a constructor
- How Exactly Does @param Work – Java
- Return string Input with parse.string
- Android ListView headers
- What does -XX:MaxPermSize do?
- What is the difference between a null array and an empty array?
- Why is there no String.Empty in Java?
- How to initialize List
object in Java? - PrintWriter append method not appending
- Using ADB to capture the screen
- What is the difference between response.sendRedirect() and request.getRequestDispatcher().forward(request,response)
- Recursion vs. Iteration (Fibonacci sequence)
- What is difference between Errors and Exceptions?
- What is the difference between Integer and int in Java?
- Static Error: This class does not have a static void main method accepting String[]
- eclipse won’t start – no java virtual machine was found
- What causes “‘void’ type not allowed here” error
- Variable might not have been initialized error
- Java substring: ‘string index out of range’
- throw checked Exceptions from mocks with Mockito
- How to sort an array of objects in Java?
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- keytool error Keystore was tampered with, or password was incorrect
- Hibernate Error: a different object with the same identifier value was already associated with the session
- How to solve the “failed to lazily initialize a collection of role” Hibernate exception
- Initializing multiple variables to the same value in Java
- Java: Unresolved compilation problem
- FXML Load exception
- NullPointerExcetion Native Method Accessor… Hashing Words Issue
- How to convert currentTimeMillis to a date in Java?
- How to clear console in Java – Eclipse
- Java TreeMap Comparator
- Determine if a String is an Integer in Java [duplicate]
- How do I run Java .class files?
- Fill an array with random numbers [duplicate]
- Connection Java – MySQL : Public Key Retrieval is not allowed
- Size has private access in ArrayList
- Iterator for a linkedlist
- Hide Utility Class Constructor : Utility classes should not have a public or default constructor
- Android – Start service on boot
- JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object
- Regular expression to limit number of characters to 10
- Sending POST data in Android
- When is “java.io.IOException:Connection reset by peer” thrown?
- Java ArrayList of Doubles
- Regular expression that matches valid IPv6 addresses
- How to extract .war files in java? ZIP vs JAR
- What is the difference between run-time error and compiler error?
- What is the difference between ArrayList.clear() and ArrayList.removeAll()?
- Test if element is present using Selenium WebDriver?
- Increase heap size in Java
- android.content.res.Resources$NotFoundException: String resource ID #0x0
- what does x– or x++ do here?
- Spring Boot – Cannot determine embedded database driver class for database type NONE
- Convert double to float in Java
- How to fix old embeded iframes with WP-CLI search-replace