Python re.match() Method
The re.match() method checks for a match only at the beginning of
the string.
If the pattern is found at the start, it returns a match object; otherwise, it
returns None.
Syntax
re.match(pattern, string, flags=0)
Parameters
| Parameter | Description |
|---|---|
pattern |
Required. The regular expression pattern to match. |
string |
Required. The string to search. |
flags |
Optional. Modify the matching behavior (e.g., re.IGNORECASE). |
Return Value
A match object if the pattern matches at the beginning, otherwise
None.
Example
Using the re.match() method:
Output
Click Run to execute your code
Enjoying these tutorials?