Regex to select eight digit number

Hi Everyone,

I want to select an eight digit number without any space or hyphen even if it presents. In the below snippet i want to select only 01299100 and regex should not take the number 00210000 by excluding - or space.

e.g toll number: +1-000-000-000

toll free number for usa: 1-000-000-0000

toll free number: 0008-00210000

sr01299100
sr 01299100

Thanks,
Ulaga

\b[0-9]{8}\b

@Tiberiu_Niculescu Thank you. This is the same I used but it selects this number “00210000” also. I don’t want it get selected. this number is actually a toll free number : 0008-00210000

Hey @Boopathi

just use this one - \b[1-9]{8}\b

Regards…!!
Aksh

Thank you but It does not match and getting this message when tried to use in https://regex101.com/

In simple

toll free number: 0008-00210000

sr01299100
sr 01299100

I want only “01299100” from the above string

try this one (?:^|\s|)[0-9]{8}(?:^|\s|)

Thank you but this also selects 00210000. Want to exclude this number 00210000 based on the - symbol used before it.

image

@Tiberiu_Niculescu. Thank you and still working to get the final result. want to get selected “01299100” and need to exclude space also and both the number “01299100” in the above snippet need to get highlighted

(?:^|\s|[a-z])[0-9]{8}(?:^|\s|)

image

Then you could use a substring(1,8) to get only the number. I’m not that good at regex.

Thank you for your help. I will try it out and Just want to clarify using the below screenshot what exactly needed.

yeah, i got it, but i don’t know the regex for that :frowning:

@Boopathi
Use ((?<=[a-zA-Z ]+)[0-9]{8}) means 8 digits after characters or space
Capture

Hey @Boopathi

Check it out -https://regex101.com/r/Xmeo3C/5

and you can use below regex pattern - (?<=[\w\s])\d{8}

Regards,!!
Aksh

1 Like

@aksh1yadav Thank you. Yes, it works and learnt a new thing today in regex.