Reputation: 231
I need to query for all rows that have a backslash character in between. This is the query I wrote:
select * from table where A = '2014-10-30' and B rlike '.asterisk\.asterisk'
(Had to manually type asterisk. The query had the symbol itself)
It is returning the entire table whether or not column B has backslash.
'.\\.' returned no rows even though there are rows where B has a backslash character.
Sample B - Hi can check the details for you/
Upvotes: 0
Views: 5124
Reputation: 19
This question well explained in this blogpost.
https://www.themarketingtechnologist.co/slashception-with-regexp_extract-in-hive/.
In short, the answer is:
Use 4 backslashes.
Upvotes: 1
Reputation: 5018
Here's the basic guide on writing regular expressions: http://tldp.org/LDP/Bash-Beginners-Guide/html/chap_04.html
If you need to check whether backslash is in the string, try "instr" function, it is much simpler tran regexp: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringFunctions
As of regexp, it should be simply this: '\\'
One more good resource for checking regexp validity online: http://regex101.com/
Upvotes: 0