EgyEast EgyEast - 9 months ago 55
C# Question

What is the C# regex format to match +- signs or space?

I've writing code using Regex format to search for numbers that has signs before it either: + , - or space like the following numbers :

( 00.00)

I'm using this format but i want to include space with +-


Please help , thanks.

Answer Source

You can use:

  • Take note of \s in the first character class [...] that will match a whitespace.
  • Unescaped hyphen should be at first or last position in character class.
  • Also, you need to escape the dot otherwise it will match any character.