How to extract 8 or 9 digits from string using regular expressions

For eg,I am having string like

TEST-OK_543210123-om sri-876543 student details to change class
from above line I need to extract 543210123
some times it can be 8 digits & sometimes it can be 9 digits. Need to extract that part of 8 or 9 digits.
Please help anyone?

use below expression

system.text.RegularExpressions.Regex.Match(strinput,"\d{8,9}").Value

here string input is your string data

Regards

1 Like

System.Text.RegularExpressions.Regex.Match(VarName,“\d{8,}”).Value
After Comma use range what you Want.

I hope this will help you

Hi @vnsatyasunil

Try this

image

I hope it helps!!

Regards,

Hey!

Try this

System.Text.RegularExpressions.RegEx.Match(YourInputVariable,“\d{8,}”).ToString

Regards,
NaNi

Hi,

FYI, another approach:

If you want to prevent to match 10 or more digits, the following might be better.

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=^|\D)\d{8,9}(?=\D|$)").Value

Regards,

1 Like

not working

Hi @vnsatyasunil

Can you try this-

\b\d{8,9}\b

Thanks!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.