Regular Expression, widely termed as Regex is a sequence of characters which forms a search pattern. It is used to match the patterns in the string or the text. Using the regex we can find a pattern and also we can replace the pattern(speaking in perspective with Java). Always regex is applied to the string or text from left to right.
Simple Example on Regex
regex : java
string : javaindetail.com
How many times regex is repeating in string? :: 1
Is regex matching string? :: no
Is regex present in string? :: yes
NOTE : Once a source character has been used in a match, it cannot be reused.
Uses of Regular Expression
- Search a pattern in string or text.
- Edit or Modify a pattern in string or text.
- To count how many times a pattern is matched.
Where Regex is used in Java
- Applied with Pattern and Matcher classes available in java.util.regex to compile and process the string based on regex.
- Applied with String.matches() to check whether the string matches the regex or not.
- Applied with String.split() to split the string with regex.
- Applied with String.replace() and String.replaceAll() to edit or modify the string based on regex.
Enjoy Reading This Article?
Here are some more articles you might like to read next: