I want to retrieve numbers from string whose character start from 8 OR 9 OR 6 and is followed by 8 digits.
E.G
sting string string 85689252 91585555 65987582 sting 12345678 string
Output should be:
85689252
91585555
65987582
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You probably want this regex:
I assume that the numbers are at least separated by some character other than alphanumeric and
_, so I used\bto match word boundary.If you want to relax the condition, the regex engine must support look ahead and look behind:
In this case, I just make sure the whole number is not preceded or followed by any digit.
Your question says followed by 8 digits, but it seems you mean the whole number should have 8 digits – so I changed my answer according to your sample input.
Use
Regex.Matchesto get all the string that matches the regex.