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.
Extract a specific group matched by the Java regex regexp, from the specified string column. If the regex did not match, or the specified group did not match, an empty string is returned.
For the corresponding Databricks SQL function, see regexp_extract function.
Syntax
from pyspark.sql import functions as dbf
dbf.regexp_extract(str=<str>, pattern=<pattern>, idx=<idx>)
Parameters
| Parameter | Type | Description |
|---|---|---|
str |
pyspark.sql.Column or str |
target column to work on. |
pattern |
str |
regex pattern to apply. |
idx |
int |
matched group id. |
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('100-200',)], ['str'])
df.select('*', dbf.regexp_extract('str', r'(\d+)-(\d+)', 1)).show()
df = spark.createDataFrame([('foo',)], ['str'])
df.select('*', dbf.regexp_extract('str', r'(\d+)', 1)).show()
df = spark.createDataFrame([('aaaac',)], ['str'])
df.select('*', dbf.regexp_extract(dbf.col('str'), '(a+)(b)?(c)', 2)).show()