pyspark.sql.functions.rlike#

pyspark.sql.functions.rlike(str, regexp)[source]#

Returns true if str matches the Java regex regexp, or false otherwise.

New in version 3.5.0.

Parameters
strColumn or str

target column to work on.

regexpColumn or str

regex pattern to apply.

Returns
Column

true if str matches a Java regex, or false otherwise.

Examples

>>> df = spark.createDataFrame([("1a 2b 14m", r"(\d+)")], ["str", "regexp"])
>>> df.select(rlike('str', lit(r'(\d+)')).alias('d')).collect()
[Row(d=True)]
>>> df.select(rlike('str', lit(r'\d{2}b')).alias('d')).collect()
[Row(d=False)]
>>> df.select(rlike("str", col("regexp")).alias('d')).collect()
[Row(d=True)]