Python regex `search` function

Python Regex search() function explained with examples.

We'll cover the following...

The Search Function

The search function searches for first occurance of a re pattern to string with optional flags.

Here is the syntax for this function −

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

Where, pattern is the regular expression to be matched, string is the string to be searched to match the pattern at the beginning of string and flags, which you can specify different flags using bitwise OR (|).

Match Flags

Modifier Description
...