How to use a regular expression and assign the result to variables in Android?
Posted
by ChengYing
on Stack Overflow
See other posts from Stack Overflow
or by ChengYing
Published on 2010-05-21T02:14:14Z
Indexed on
2010/05/21
2:30 UTC
Read the original article
Hit count: 270
I have a string named s_Result
which will be parsed from the Internet. The format may be "Distance: 2.8km (about 9 mins)"
, and there are 4 variables which are f_Distance
, m_DistanceUnit
, f_timeEst
, m_timeEstUnit
.
My question is how to parse s_Result
and assign 2.8
, km
, 9
, mins
into f_Distance
, m_distanceUnit
, f_timeEst
and m_timeEstUnit
respectively using regular expression?
I tried using "\d+(\.\d+)?"
in RegEx Tester and the result showed 2 matches found, but if I use "\\d+(\\.\\d+)?"
in Android code, it showed no matches!
Any suggestions what might be going wrong?
© Stack Overflow or respective owner