if the value has a "." it trims the string there (i.e for property3 it returns val but it should return value3)
That's because \\w+
matches alphanumeric characters and underscore, it doesn't match dot characters .
.
it doesn't trim the value in a new line or a space (sometime it returns - "value2\r")
I can see how this might be happening because as I said above a \\w+
matches word characters so once it spots any other character it stops matching.
A better regex:
Since the name of the property is passed in, we have one task left and that is to match the value, since values are always to end with a newline \n
, carriage return \r
or dots .
then we could match one or more characters that are neither of those to capture the value, something like this:
{0}\\s*([^\\r\\n ]+)
^^
There is a space here, don't forget it
Notice there is a single space
after the \\n
in the character class above.
RegexHero Demo