i

Python Programming

The search function

Search function searches for first occurrence RE pattern within string with optional flags.

The syntax for function:

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

Parameter & Description

pattern

Regular expression to be matched.

string

It is the string which would be searched to match the pattern anywhere in the string.

Flags

We can specify different flags by using bitwise OR. These are modifiers listed in table below.

The re.search function returns match-object when success, none on failure, group(num) or groups() function of match object generally to get matched-expression.