08 Regular Expressions Flashcards
Also known as regex, it is a character or a sequence of characters that represent a string or multiple strings.
Regular expression
What is the package used for regular expressions?
java.util.regex;
What is the method that returns true if a string matches the given regular expression?
matches(String regex)
It is the wildcard operator that represents any single character in regular expressions.
dot (.)
It is any symbol in regular expressions that indicates the number of times a specified character appears in a matching string.
Repetition Operator
What are the repetition operators?
*
?
+
{x}
{x,y}
{x,}
Repetition operator when there is 0 or more occurrences.
*
Repetition operator when there is 0 or 1 occurrence.
?
Repetition operator when there is 1 or more occurrence.
+
Repetition operator when there is an x number of occurences.
{x}
Repetition operator when there is a number between x & y occurrences.
{x,y}
Repetition operator when there is a number of x or more occurrences.
{x,}
Class that stores the format of a regular expression.
Pattern class
A method that compiles the give regular expression into a pattern.
compile()
Class that stores a possible match between a pattern and a string.
Matcher class
Method that scans the input sequence looking for the next subsequence that matches the pattern.
find()
Method that splits the string around matches of the given regular expression.
split()
Method that is used to replace all the occurrences of the defined regular expression found in the string with another string.
replaceAll()