Sublime Forum

Regex Optional Cases

#1

Hi ! I wouldlike to know a regex formation who match with my exemple, pls :confounded:
It’s composed of 3 of more elements separate by spaces.
First, the letter a which always needs to be here (compulsory).
After, a b ā€œoptionalā€ element, which can be b1 or b2, b3… When I say optional that means this element can just be not here.
Then, other optionals elements like b: for c it will be c1 or c2, c3… BUT the trick is that when you don’t write an element, the match needs to stop just before it. That means if you omit one optional element all the other on his right will don’t match too. So do you understand ? I really hope yes, thank you in advance !

0 Likes

#2

a((b1|b2|b3)(c1|c2|c3)?)?

1 Like

#3

I already try this, maybe it is’nt a bad way. Do you think there is an other answer, this way will be not very useful with a lot of optionals elements, no ? And you forget the spaces between ^^

0 Likes