问题
I am using spark SQL and trying to compare a string using rlike
it works fine, however would like to understand how to ignore case.
this return true
select "1 Week Ending Jan 14, 2018" rlike "^\\d+ Week Ending [a-z, A-Z]{3} \\d{2}, \\d{4}"
However, this return False,
select "1 Week Ending Jan 14, 2018" rlike "^\\d+ week ending [a-z, A-Z]{3} \\d{2}, \\d{4}"
回答1:
Spark is using the standard Scala regex library, so you can inline the processing flags in the pattern, for example (?i) for case-insensitive:
spark.sql("""select "1 Week Ending Jan 14, 2018" rlike "(?i)^\\d+ week ending [a-z, A-Z]{3} \\d{2}, \\d{4}"""").show()
+--------------------------------------------------------------------------------+
|1 Week Ending Jan 14, 2018 RLIKE (?i)^\d+ week ending [a-z, A-Z]{3} \d{2}, \d{4}|
+--------------------------------------------------------------------------------+
| true|
+--------------------------------------------------------------------------------+
来源:https://stackoverflow.com/questions/57118843/spark-sql-rlike-ignore-case