Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Regular expressions in python
  5. Match Function

Match Function

Regular expression in is a sequence of characters that forms a search pattern.

t is used to confirm whether the string has that particular term or not.

We can easily import regular expression in python.

  • [] – A set of characters
  • \ – Signals a special sequence.
  • . – Any character
  • ^ – Starts with
  • $ – Ends with
  • * – Zero or more occurrence
  • + – One or more occurrence
  • {} – Exactly the specified number of occurrences.
  • | – Either or
  • () – Capture and group

Special sequence:-

  • \d Matches any decimal digit, this is equivalent to the set class [0-9].
  • \D Matches any non-digit character.
  • \s Matches any whitespace character.
  • \S Matches any non-whitespace character
  • \w Matches any alphanumeric character, this is equivalent to the class [a-zA-Z0-9_].
  • \W Matches any non-alphanumeric character.

This function attempts to match RE pattern to string with optional flags.


re.match(pattern, string, flags=0)


import re
s='''Python is one of the most popular programming languages in the world.'''
print(re.match(a, s, re.IGNORECASE))

This is all about match function in python.

Was this article helpful to you? Yes No

How can we help?