0% found this document useful (0 votes)
6 views1 page

Regular Expression Explanation

Uploaded by

ltan22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Regular Expression Explanation

Uploaded by

ltan22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Student ID: 22127005

Full name: Lê Thiên Ân

Basic regular expression


A regular expression (regex) is a sequence of characters that defines a search pattern, commonly
used for string matching and manipulation.
Basic characters: abc… ABC… 0123… and “_”.
1. “.”: every single character (A-Z, a-z, 0-9, _, space, ~, !, …). Thus, a single dot (.) will be
presented by “\.”.
Example: abc, 123xyz, …
2. [abc]: only acept a specific single character of a or b or c.
Example: alien, bat, cat, …
3. [^abc]: accept every character except a and b and c. It is the oposite of [abc].
Example: dog, fish, …
4. [A-Z], [a-z], [0-9]: character ranges. It will match the character in range from A to Z, a to
z or 0 to 9 (case-sensitive).
5. “\w”: [A-Za-z0-9_]
Example: “\w” will match Abc, 1234, _hello, …
6. {n, m}: repeat at least n times and maximum m times. The m can be left with a blank to
indicate that it can repeat infinite times. We can also keep the n only {n}, which means
the sequence must repeat exactly n times.
Example: “Hi{1, 4}” matches Hi, Hii, Hiii, Hiiii. “Hi{3}” only matches Hiii.

7. *: from 0 to ∞repetitions. The character before the “*” can repeat 0 or more times.

Example: \d* will match a string containing a number like 123, 2024, …

8. +: from 1 to ∞ repetitions. The character before the “+” must repeat at least 1 time.

Example: “Hi*” will match Hi, Hii, Hiii, ….


9. ?: optional character. The character before “?” can exist or not.
Example: “ab?c” with match whether abc or ac since the “b” is optional.
10. \s: any whitespace (space “ ”, tab \t, newline \n).
Other components:
Starts with ^ and ends with $, capture group with (…), and or “|” operator.
\W, \D, \S are the oposite of \w, \d, \s.
Reference: https://regexone.com/

You might also like