Part 5 - Regular Expressions Flashcards
What is a regular expression?
A regular expression is a set of special characters that define a pattern
What is the difference between a literal and a metacharacter?
- A literal is just a character you wish to match in the target
- A metacharacter is a special symbol that acts as a command to the regular expression parser
In a regular expression, what does it indicate when the expression has the following form?
^example_expression$
The entire string must match the rest of the regex between the ^ and $
What is the meaning of - \t -\n - . in regex?
- \t matches any tab character
- \n matches any new line character
- . matches any character that is not \n
What is the difference between [example], [^example] and [e-l]?
[] - match any character contained in the set
[^] - match any character NOT in the set
[a-h] - match any character in the range
What is the difference between \w and \W?
\w matches any word character
\W matches any non-word character
What is the meaning of \s and \d in regex?
- \s match any white-space character
- \d match any digit character
In regex, what is indicated by *, +, and ?
- Indicates zero or more matches
- Indicates one or more matches
- ? Indicates zero or one match
Using {}, how would you indicated n or more matches?
{n,}
What is the boolean OR equivalent metacharacter in regex?
|
How can a metacharacter, for example “?”, be used as a literal
Preface with \
How would you ensure that a string contains uppercase letters, no matter where they are placed?
(?=.*[A-Z])