Regular Expression to get only number from sentence

Dear All,

I hope to get only number from sentence by using Regular Expression.
Could you please let me know how to do it!?

image
/url/prd/429791 → 429791
/url/prd/437316?recopick=46&product_type=R → 437316

thanks,
Best regards,

Hi,

Is there any rule about the target?
If it’s always 6 digits, the following will work.

System.Text.RegularExpressions.Regex.Match(yourString,"\b\d{6}\b").Value

Regards,

1 Like

@Yoichi - I was typing the same thing …you beat me :wink:

2 Likes

Hello!

It works well! Thank you so much :slight_smile:
image

Could I ask one more question?
If the number is over 6 digit, How can I get only 6 digit from left?

When I used your Regular Expression, It became ‘blank’,

thanks,
Best regards,

@Printf7 - Please try as shown below…

from Left

from Right

1 Like

Wow I really appreciate about your advice!
It works well… There is no blank.

However, I’m really sorry… I think that I should select Yoichi-san’s answer because it was posted earlier.

Thank you so much for your professional advice again and Have a nice day!

1 Like

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