0

I'm having such string: (Reasoncode1 -49.00)

From that string I need to take all the decimal values both positive/ negative so --> -49.00 I've created such regexp: -?\d+\.*\d* It work but if the string has number inside like: "Reasoncode1" then it takes that one value and I want to avoid it.

Kermi
  • 227
  • 1
  • 13
  • You can use: `-?\b\d+(?:\.\d+)?` – anubhava Oct 14 '22 at 06:17
  • Why not use `Decimal.TryParse`? – Dai Oct 14 '22 at 06:17
  • This really depends on your target inputs generally. Pranjal Patel's solution works, but if there's some input like `Reasoncode1.0 -49.00` then similar issue happens. If there isn't then you can choose that solution as correct answer. If they all follow `string number` format, you can also consider `.Split()` and take the 2nd element for TryParse. – Xiang Wei Huang Oct 14 '22 at 08:10

1 Answers1

-1

Try this regex

-?[0-9]*\.[0-9]*