re.match() in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report re.match method in Python is used to check if a given pattern matches the beginning of a string. It’s like searching for a word or pattern at the start of a sentence. For example, we can use re.match to check if a string starts with a certain word, number, or symbol. We can do pattern matching using re.match in different ways like checking if the string starts with certain characters or more complex patterns. Python import re # Checking if the string starts with "Hello" s = "Hello, World!" match = re.match("Hello", s) if match: print("Pattern found!") else: print("Pattern not found.") OutputPattern found! Table of ContentSyntax of re.matchUsing re.match with Regular ExpressionsAccessing Match ObjectSyntax of re.matchre.match(pattern, string, flags=0)Parameterspattern: This is the regular expression (regex) that you want to match. It can be any string that defines a pattern, like r"\d" for a digit, or r"[A-Za-z]" for any letter (uppercase or lowercase).string: This is the string you want to check for the pattern. re.match will try to match the pattern only at the beginning of the string.flags (optional): This is an optional parameter that allows you to modify how the matching should behave. For example, you can use re.IGNORECASE to make the matching case-insensitive. If not provided, the default value is 0.ReturnsIf re.match finds a match at the beginning of the string, it returns a match object.If no match is found, it returns None.Using re.match with Regular ExpressionsRegular expressions (regex) allow us to search for more complex patterns. For example, let’s check if a string starts with a number. Python import re # Checking if the string starts with a number s = "123abc" # \d means any digit match = re.match(r"\d", s) if match: print("Starts with a number.") else: print("Doesn't start with a number.") OutputStarts with a number. Accessing Match ObjectThe result of re.match is a match object if a match is found, or None if no match is found. If a match occurs, we can get more information about it. Python import re s = "Python is great" match = re.match(r"Python", s) if match: print(f"Match found: {match.group()}") # .group() returns the matched string else: print("No match.") OutputMatch found: Python Create Quiz Comment P pragya22r4 Follow 2 Improve P pragya22r4 Follow 2 Improve Article Tags : Python python-regex python Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like