Link to home
Start Free TrialLog in
Avatar of Nitin Sontakke
Nitin SontakkeFlag for India

asked on

C# Regular Expression Help required.

I need help identifying a regular expression pattern to find the number of occurrences of a specific pattern within a given string.
 
For example, the pattern to be sought is "1" followed by 2 or more zeros and then followed by "1".
 
As such, "00010000011110001111000000100", would have 3 matches. I manage to do this successfully, with the help of pattern ""[1]0+0+[1]".
 
The more complicated one which I am not been able to handle is:
 
"000100001000001001000000101000000000" should be returning 4 matches. This is because a single 1 at position 9 will be used for pattern matching on either side.
 
In RegEx technical terms, I think,, this is called "Backreference constructs", which I am not been able to implement correctly.

I also need an exactly opposite pattern too, which is "0" followed by 2 or more ones and then followed by "0". However, I believe it can easily be done by just flipping numbers around from one correct answer.
Avatar of ozo
ozo
Flag of United States of America image

10+0+(?=1)
ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nitin Sontakke

ASKER

Thanks, Dan. Let me run this through some test case strings and come back to you. Thanks, again!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I do admit that this is taking longer than expected. Please stand by when this is being evaluated. Primary evaluation does look okay, though!
Thanks, everybody!