I want to retrieve a number from a string wherever the number starts with 8,9 or 6 and length of the number should be 8 OR 9 Characters. E.g 92000000,9200 0000,9200-0000.
Share
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.
How about this:
(?<!\d)([896]\d{3})(?:[-\s]?)(\d{4})(?!\d).The
(?:[-\s]?)eats the optional delimiters space or dash as a non-capturing group.You get your number by concatenating the match groups 1 and 2:
I have also tried
(?<!\d)([896]\d{3}(?:[-\s]?)\d{4})(?!\d)and that won’t remove the delimiter character from the match result.