Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Returns a count of the number of times that the Java regex pattern regexp is matched in the string str.
For the corresponding Databricks SQL function, see regexp_count function.
Syntax
from pyspark.sql import functions as dbf
dbf.regexp_count(str=<str>, regexp=<regexp>)
Parameters
| Parameter | Type | Description |
|---|---|---|
str |
pyspark.sql.Column or str |
target column to work on. |
regexp |
pyspark.sql.Column or str |
regex pattern to apply. |
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([("1a 2b 14m", r"\d+")], ["str", "regexp"])
df.select('*', dbf.regexp_count('str', dbf.lit(r'\d+'))).show()
df.select('*', dbf.regexp_count('str', dbf.lit(r'mmm'))).show()
df.select('*', dbf.regexp_count("str", dbf.col("regexp"))).show()
df.select('*', dbf.regexp_count(dbf.col('str'), "regexp")).show()