1

How do I write a regular expression in where clause to match the following patterns

Pattern 1

~
~ ~
~ ~ ~

Pattern 2

~ ~ |A~b
~ ~ ~|A~b~c
~ ~ ~|this can be anything
~ ~ ~ ~ ~ ~|this can be anything

For pattern 2 just need to match the part before |.

1
  • Something like REGEXP '^[~ ]{2,6}|.*';? Commented Feb 26, 2015 at 9:47

1 Answer 1

1
^~([ ]+~)*[ ]*(\\|.*|$)

Try this.If you have space before first ~ use

^[ ]*~([ ]+~)*[ ]*(\\|.*|$)

See demo.

http://www.sqlfiddle.com/#!2/b67085/3/0

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. However, this is also brining ~B~ ~ ~|3~1~2~0~ in the result. There should not be anything between ~'s
Hi, Sometimes I am getting this error when I execute the query. Got error 'empty (sub)expression' from regexp. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.