Let's take a look at the regex you are using:
^\s*?([\d\,]+(\.\d+)?|\.\d+)\s*$
First symbol is ^
, which stands for a start of a line. \s
is a space symbol, *
says this symbol can occur many times, ?
symbol stands for a 0 or greater
space occurrences. So this group of symbols simply cuts out the whitespace at the line start.
The similar sequence can be found at the end of the regex, it goes without ?
sign, which, as I think, can be copied to the left side of your regex, and $
stands for a line ending.
In between of this space-cutting constructs you may find the main checking for a numeric string, which says that number can contain any sequences of digits and thousand separator ([\d\,]+
says that we are searching for a one or greater
number of occurrences for digit with trailing thousand separator) after which we can or can not find the decimal separator and digits after it.
So, the change you want to do is quite simple, you only have to add check for a -
sign with question mark at the start of the main symbol group, like this:
^\s*?(-?[\d\,]+(\.\d+)?|\.\d+)\s*$
You can find more useful regex samples here.