Reputation: 418
I'm using Unity 5.3.4 and using C#. I was wondering if it would be possible to extract with regular expressions the value in this string, I do need the sign, as now is negative but it doesn't have to be that way:
string str = " "rssi": "-56", "
I do know that to use regular expression in unity it would be this way:
str = Regex.Replace(str, "*regular expression*", String.Empty);
I was wondering what would be a proper regular expression. I've been trying some in http://www.regexr.com/ But with no luck. I'll keep trying.
Upvotes: 1
Views: 465
Reputation: 418
Just found the solution:
Regex rgxNumber = new Regex("([-+]{0,1}[0-9]+)");
Match mNumber = rgxNumber.Match(str);
string result = mNumber.Groups[1].Value;
Hope it helps someone else.
Upvotes: 1
Reputation: 2691
You can use following regular expresstion :[-+]?\d+
Meaning: get the one or more digits may be followed by sign.
Upvotes: 1