Question:
question about regular expressions?
2009-08-17 19:55:28 UTC
: generate a string that has an even number of 0s and an odd number of 1s.

in some programming languages, identifiers may have embedded underscore characters. However,the first character may not be an underscore, nor may two underscores appear in succession. Write a regular expression that generates such identifiers.
Three answers:
?
2009-08-17 20:11:46 UTC
Regular expressions don't generate anything. They match patterns -- nothing more and nothing less.



Assuming all the 0's come first and all the 1's come last, a regular expression that will match an even number of 0's followed by an odd number of 1's would be (assuming 0 is considered "even"):



(00)*1(11)*



A valid identifier by the above rules would be matched by:



[a-zA-Z0-9]+(_[a-zA-Z0-9]+)*_?
eberline
2016-12-16 13:51:07 UTC
generally occurring expressions is the incorrect device for this and it extremely is almost impossible to get all 3 of those right into a unmarried regexp. you're able to do it in 2 nevertheless: a million and 3) ^[a-zA-Z0-9]{8,}$ clarification: From the putting out to the tip, experience purely letters and numbers 8 or extra circumstances. 2) ^[^0-9]*[0-9][^0-9]*[0-9].*$ clarification: From the commencing up, experience any non-huge style 0-n circumstances, then experience the 1st huge style, then experience any non-huge style 0-n circumstances, then experience the 2nd huge style, then settle for something of the enter to the tip. replace: I examined and shown "eli porter"'s answer. it extremely works and that i defer to his better answer. "husoski"'s does not artwork because it helps underscores.
1234
2009-08-17 20:08:29 UTC
nope


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...