Getting Ranged Number in a String

Hi All,

I’m trying to get a range of number from a string.

Input:- Volume to be considered is 1-3.
Expected Output: 1-3

System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"\D","")
With the above code, am getting the output is 13

Can anyone please suggest me how to solve this issue.

Use \d{0,3} or \d{1,3}.
System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"\d{1,3}","")

1 Like

@Manish540,

Could you please check your code, it is not giving the expected output.

Hi,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(string_Variable,"\d+-\d+").Value

Regards,

2 Likes

Use this,
System.Text.RegularExpressions.Regex.Replace(“string_Variable”,"\d{0,9}\-\d{0,9}","")

Thank you @Manish540 and @Yoichi

1 Like

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