Spark SQL rlike to find all strings with trailing numbers -
while querying data frame have tried use rlike without success.
sample data:
column_a|column_b 1|abc xyz 2|123 abc xyz 3|abc 123 xyz 4|abc 123 5|xyz 123 expected output:
column_a|column_b 4|abc 123 5|xyz 123 i have tried:
select * table_1 column_b rlike '\d+$' (select * table_1 column_b rlike '/\d+$') output (no results):
column_a|column_b i've tried:
select * table_1 column_b rlike '\d*$' (select * table_1 column_b rlike '/\d*$') output (all rows):
column_a|column_b 1|abc xyz 2|123 abc xyz 3|abc 123 xyz 4|abc 123 5|xyz 123 is regex incorrect? have tested using python , online tester , looks correct. or rlike support specific regex?
you'll need bit more escaping make work. in particular:
spark.sql("select 'abc 123' rlike '\\\\d+$'").show() +------------------+ |abc 123 rlike \d+$| +------------------+ | true| +------------------+ spark.sql("select '123 abc xyz' rlike '\\\\d+$'").show() +----------------------+ |123 abc xyz rlike \d+$| +----------------------+ | false| +----------------------+
Comments
Post a Comment