Regex Match not working to keep only matched entities

I intend to keep all the numbers (including decimals) and convert them into Double Variable. But these numbers are mixed with alphabets as shown below:

2eq3wecesf4 => 234
vre435vfdvb => 435
efwer4.545dv => 4.545

The matches should work as given in the above example, it’s given that a decimal will occur only once. I am using this regular expression: [0-9]|\.

Even though this tests fine on regex101, when I use it like this:
System.Text.RegularExpressions.Regex.Match(in_number,"[0-9]|\.").ToString

for the input: "asdfsvret234vdvsfbeg0" I get only 2.

Not sure whats going wrong.

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"[^.\d]","")

Regards,

1 Like

Thanks this worked. :slight_smile:

1 Like

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