Pattern 1:Delimited by |
Input : a|b|c|d
Output: a|b|c|d
Pick everything when delimited by a single pipe
Pattern 2:Delimited by | and ||
Example1:
Input :a|b||c||d
Output:a|b||c
Pick everything before last double pipe
Example2:
Input :a|b||c|d
Output:a|b
Pattern 3:Beginning of the string can have multiple pipes(odd or even) and further be deilimited by | and ||
Input :|||a|b||c||d
Output:|||a|b||c
Pick everything before last double pipe ,beginning of the string might have odd or even pipes and they must be selected.
Below covers all except scenario 1,My requirement is to cover all scenarios in one regexp_extract spark.sql("select regexp_extract('name|place|thing|ink', '(.*)(?=\\\\|\\\\|)') as demo").show(false)
If it can not be done in one regexp_extract.Can you suggest other options.
Please advise.