pyspark.pandas.Series.str.match

str.match(pat: str, case: bool = True, flags: int = 0, na: Any = nan) → pyspark.pandas.series.Series

Determine if each string matches a regular expression.

Analogous to contains(), but more strict, relying on re.match() instead of re.search().

Parameters
patstr

Character sequence or regular expression.

casebool, default True

If True, case sensitive.

flagsint, default 0 (no flags)

Flags to pass through to the re module, e.g. re.IGNORECASE.

nadefault NaN

Fill value for missing values.

Returns
Series of boolean values or object

A Series of boolean values indicating whether the given pattern can be matched in the string of each element of the Series.

Examples

>>> s = ps.Series(['Mouse', 'dog', 'house and parrot', '23', np.NaN])
>>> s.str.match('dog')
0    False
1     True
2    False
3    False
4     None
dtype: object
>>> s.str.match('mouse|dog', case=False)
0     True
1     True
2    False
3    False
4     None
dtype: object
>>> s.str.match('.+and.+', na=True)
0    False
1    False
2     True
3    False
4     True
dtype: bool
>>> import re
>>> s.str.match('MOUSE', flags=re.IGNORECASE)
0     True
1    False
2    False
3    False
4     None
dtype: object