Regex for bit string containing at least 2 zeros but no consecutive zeros.
up vote
0
down vote
favorite
This is what I have:
(1*011*011*)*
But I don't think this is accounting for an odd number of zeros, like "10101010101111". I think I have the right expression that satisfies no 2 consecutive zeros and even number of zeros.
regular-expressions
add a comment |
up vote
0
down vote
favorite
This is what I have:
(1*011*011*)*
But I don't think this is accounting for an odd number of zeros, like "10101010101111". I think I have the right expression that satisfies no 2 consecutive zeros and even number of zeros.
regular-expressions
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
This is what I have:
(1*011*011*)*
But I don't think this is accounting for an odd number of zeros, like "10101010101111". I think I have the right expression that satisfies no 2 consecutive zeros and even number of zeros.
regular-expressions
This is what I have:
(1*011*011*)*
But I don't think this is accounting for an odd number of zeros, like "10101010101111". I think I have the right expression that satisfies no 2 consecutive zeros and even number of zeros.
regular-expressions
regular-expressions
asked Dec 3 at 19:19
pinklemonade
836
836
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I'll get you started.
You need to have two zeroes, so start by putting those in your regex, leaving space between, before and after:
$$
______0______0______
$$
Now, consider the space on the left. Every zero in this region is followed by a $1$. Therefore, this portion can be broken into sums of $(01)$ and $1$, so it is $(01|1)^*$:
$$
(01|1)^*0______0______
$$
What about the space in the middle? It has similar rules, but we cannot quite use the same regex $(01|1)^*$ we used on the left. The problem is that this can begin with a zero, which would cause a $00$ with the first $0$ we placed. How can you fix this?
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I'll get you started.
You need to have two zeroes, so start by putting those in your regex, leaving space between, before and after:
$$
______0______0______
$$
Now, consider the space on the left. Every zero in this region is followed by a $1$. Therefore, this portion can be broken into sums of $(01)$ and $1$, so it is $(01|1)^*$:
$$
(01|1)^*0______0______
$$
What about the space in the middle? It has similar rules, but we cannot quite use the same regex $(01|1)^*$ we used on the left. The problem is that this can begin with a zero, which would cause a $00$ with the first $0$ we placed. How can you fix this?
add a comment |
up vote
0
down vote
I'll get you started.
You need to have two zeroes, so start by putting those in your regex, leaving space between, before and after:
$$
______0______0______
$$
Now, consider the space on the left. Every zero in this region is followed by a $1$. Therefore, this portion can be broken into sums of $(01)$ and $1$, so it is $(01|1)^*$:
$$
(01|1)^*0______0______
$$
What about the space in the middle? It has similar rules, but we cannot quite use the same regex $(01|1)^*$ we used on the left. The problem is that this can begin with a zero, which would cause a $00$ with the first $0$ we placed. How can you fix this?
add a comment |
up vote
0
down vote
up vote
0
down vote
I'll get you started.
You need to have two zeroes, so start by putting those in your regex, leaving space between, before and after:
$$
______0______0______
$$
Now, consider the space on the left. Every zero in this region is followed by a $1$. Therefore, this portion can be broken into sums of $(01)$ and $1$, so it is $(01|1)^*$:
$$
(01|1)^*0______0______
$$
What about the space in the middle? It has similar rules, but we cannot quite use the same regex $(01|1)^*$ we used on the left. The problem is that this can begin with a zero, which would cause a $00$ with the first $0$ we placed. How can you fix this?
I'll get you started.
You need to have two zeroes, so start by putting those in your regex, leaving space between, before and after:
$$
______0______0______
$$
Now, consider the space on the left. Every zero in this region is followed by a $1$. Therefore, this portion can be broken into sums of $(01)$ and $1$, so it is $(01|1)^*$:
$$
(01|1)^*0______0______
$$
What about the space in the middle? It has similar rules, but we cannot quite use the same regex $(01|1)^*$ we used on the left. The problem is that this can begin with a zero, which would cause a $00$ with the first $0$ we placed. How can you fix this?
answered Dec 3 at 21:07
Mike Earnest
19.6k11950
19.6k11950
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3024541%2fregex-for-bit-string-containing-at-least-2-zeros-but-no-consecutive-zeros%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown