Regular expressions use in String of Java
Regular expressions are used to define the symbols. Regular Expressions or Regex (in short) is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java.
Let's look at different symbol and suitable conditions to use them.
Matching symbols: These symbols are meant for single alphabets.
- ‘.’ it means any letter or the symbol from the keyboard.i.e for a single alphabet it is true.
- [abc]: range or set of characters/ the string is true if the alphabet is either a or b or c.
- [abc][vz]: range of multiple symbol/the string is true if first symbol is among a,b &c and second symbol is among v & z.
- [^abc]: the string is true if the symbol is other than a, b, & c.
- [a-z 1-7]: the string is true if the symbol is from the range a-z or 1-7.
- A|B: it is true for single alphabets fro either A or b.
- XZ: to check whether the string maybe either a single or multiple alphabets.
Meta characters: These are charcters with special meaning.
- \d: it will be true if it is a digit among 0-9.
- \D: it will be true if it is any symbol other than digits.
- \s: it will be true if there is just a space.
- \S: it will be true if there are any symbols other than space.
- \w: it will be true if it is either alphabet or digits.
- \W: it will be true if it is any symbol other than alphabets or digits.
String matching with regular expressions:
Quantifiers : these are used to define the number of symbols you want and quantifiers define quantities.
- ’*’ it represents number of occurrences of any of the characters for zero or more times.
- ’+’ it represents number of occurrences of any of the character for one or more times.
- ’?’ it represents number of occurrences of any of the characters for zero or one time.
- {X} it represents any of the characters for the size of X value given.
- {X, Y} it represents any of the characters for the min and max size given.
Important note: Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints.

