Thursday, 15 March 2012

regex - Regular expression deppending on number of characters and presence of specific characters -



regex - Regular expression deppending on number of characters and presence of specific characters -

my alphabet {0,1}. want match token odd (or even) number of symbols, must contain @ to the lowest degree 1 0 , @ to the lowest degree 1 1. tried regular expression:

^(?=0*?1)(?=1*?0)[01](?:[01]{2})*

but matches 11111 if input 111110 , not correct.

since sounds automata theory, here reply based on that.

you should able come 7-state dfa below:

click on image see enlarged version.

the dfa on left length string , 1 on right odd length string. label on state "[current length (odd or even)]/[0 encountered][1 encountered]".

then can solve equation final state... or utilize jflap you.

regular look odd-length string (can used in favorite regex flavor):

((11)+0|(00)+1|(10|01|(11)+10|(00)+01)[10])([10]{2})*

and even-length string:

(10|01|(11)+(10|0[10])|(00)+(01|1[10]))([10]{2})*

regex symbols

No comments:

Post a Comment