Nitin Sontakke
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, "0001000001111000111100000 0100", 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:
"0001000010000010010000001 0100000000 0" 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.
For example, the pattern to be sought is "1" followed by 2 or more zeros and then followed by "1".
As such, "0001000001111000111100000
The more complicated one which I am not been able to handle is:
"0001000010000010010000001
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.
10+0+(?=1)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Dan. Let me run this through some test case strings and come back to you. Thanks, again!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I do admit that this is taking longer than expected. Please stand by when this is being evaluated. Primary evaluation does look okay, though!
ASKER
Thanks, everybody!