I have the following regular expression:
\s?(\w+)=(\w+)?\s?
My input is
Brutto=57.800
The match is just
Brutto=57
What can I do to get the following result?
Brutto=57.800
I have the following regular expression:
\s?(\w+)=(\w+)?\s?
My input is
Brutto=57.800
The match is just
Brutto=57
What can I do to get the following result?
Brutto=57.800
I would just get all "non-space" chars:
\s?(\w+)=(\S*)\s?
FYI (\S*) has the same effect as (\S+)?, but is simpler.
You can use something like if the value always contains a decimal point \s?(\w+)=(\d+.\d+)?\s?
You must handle the dot separately (and escape it with a backslash):
\s?(\w+)=(\w+\.?\w+)?\s?
If u need just matching u can try \s?\w+=\d+.\d+\s?.
If u need grouping also u can try \s?(\w+)=(\d+.\d+)\s?
u can also replace \d with \w as \d represents only digits whereas \w represents any Alphanumeric characters.
In your regex you use \w+ which does not match the dot in 57.800 that so it would match 57.
If your goal is to match digits after the equals sign with an optional whitespace character \s? at the start and at the end, you might use:
Note that I have not use captured groups (). If you want to retrieve your matches using groups, you could use (\w+) and ([0-9]+\.[0-9]+)
If the .800 is optional you could use \s?\w+=[0-9]+(?:\.[0-9]+)?\s?