Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在pyspark中使用多个正则表达式组?_Regex_Apache Spark_Pyspark_Apache Spark Sql_Regex Group - Fatal编程技术网

Regex 如何在pyspark中使用多个正则表达式组?

Regex 如何在pyspark中使用多个正则表达式组?,regex,apache-spark,pyspark,apache-spark-sql,regex-group,Regex,Apache Spark,Pyspark,Apache Spark Sql,Regex Group,我想在两个正则表达式组之间插入一个符号 我的代码如下: df = spark.createDataFrame([('ab',)], ['str']) df = df.select( concat( regexp_extract('str', r'(\w)(\w)', 1), # extract the first group lit(' '), # add symbol regexp_extract('st

我想在两个正则表达式组之间插入一个符号

我的代码如下:

df = spark.createDataFrame([('ab',)], ['str'])
df = df.select(
  concat(
    regexp_extract('str', r'(\w)(\w)', 1),  # extract the first group
    lit(' '),                               # add symbol
    regexp_extract('str', r'(\w)(\w)', 2)   # add the second group
  ).alias('d')).collect()
print(df)

有更好的方法吗?

您可以使用
regexp\u替换
捕获组:

import pyspark.sql.functions as F

df.select(F.regexp_replace('str', r'(\w)(\w)', '$1 $2').alias('d')).show()
+---+
|  d|
+---+
|a b|
+---+

谢谢我尝试用标准的
re
组标记替换('str',r'(\w)(\w)(\w)“,\1\2'),但没有成功。pyspark中
$
的使用是否有文档记录?没有,这是java正则表达式的一个特性