0% found this document useful (0 votes)
41 views

Regular Expression

Regular expressions (regex) allow users to define search patterns to match strings of text. The regex pattern ^a...s$ matches any five letter string starting with a and ending with s. Metacharacters like [], ^, $, *, +, ?, {} are used to define more complex patterns, matching things like character sets, start/end of strings, repetition, and grouping. Common metacharacters include square brackets for character sets, period for any single character, caret for start of string, and dollar for end of string.

Uploaded by

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

Regular Expression

Regular expressions (regex) allow users to define search patterns to match strings of text. The regex pattern ^a...s$ matches any five letter string starting with a and ending with s. Metacharacters like [], ^, $, *, +, ?, {} are used to define more complex patterns, matching things like character sets, start/end of strings, repetition, and grouping. Common metacharacters include square brackets for character sets, period for any single character, caret for start of string, and dollar for end of string.

Uploaded by

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

Regular Expression

Regular Expression
• A Regular Expression (RegEx) is a sequence of characters that defines
a search pattern.
• Ex: ^a…s$
.
• The above code defines a RegEx pattern. The pattern is: any five letter
string starting with a and ending with s.
• To specify regular expressions, metacharacters are used. In the above
example, ^ and $ are metacharacters .
• Metacharacters are characters that are interpreted in a special way by a RegEx
engine. Here's a list of metacharacters:
[] . ^ $ * + ? {} () \ |
• [] - Square brackets specifies a set of characters you wish to match.
• [abc] will match if the string you are trying to match contains any of
the a, b or c.
• You can also specify a range of characters using - inside square brackets.
[a-e] is the same as [abcde].
[1-4] is the same as [1234].
[0-39] is the same as [01239].
• You can complement (invert) the character set by using caret ^ symbol at the
start of a square-bracket.
[^abc] means any character except a or b or c.
[^0-9] means any non-digit character.
• special character is the period (/./), a wildcard expression that
matches any single character (except a carriage return)

• The caret symbol ^ is used to check if a string starts with a certain


character.
• The dollar symbol $ is used to check if a string ends with a certain
character.
• Example: RegEx [0-9]{2, 4} matches at least 2 digits but not more than 4
digits .
Operator precedence
Regular Expression
• https://www.programiz.com/python-programming/regex

You might also like