ajm
ajm

Reputation: 13213

How to write mysql regular expression in where clause?

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 |.

Upvotes: 1

Views: 210

Answers (1)

vks
vks

Reputation: 67968

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

Try this.If you have space before first ~ use

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

See demo.

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

Upvotes: 1

Related Questions