Search code examples
apache-spark-sqlamazon-redshift

REGEXP_COUNT equivalent in Spark SQL


Is there an equivalent function in Spark SQL that does what REGEXP_COUNT do as in redshift?

Basically I'm trying to count the number of substrings.

REGEXP('1->2->3->456', '->')

should return 3.


Solution

  • Regexp_count is available in Spark 3.4.0, so you can try upgrading your spark version.

    Ref doc - https://spark.apache.org/docs/3.4.0/api/sql/#regexp_count