Ruby Regex extract numbers -
i wanted grab numbers between td 's , store in data. used * represent information want get.
data = data.match(<td class="yfnc_tabledata1">*</td>)
regex expression grabing numbers in general complicated one, because numbers come in kinds of shapes , colors. need decide kinds of numbers interested in, integers, with/without sign, floats, exponential notation, accept/not accept leading +... try @ http://regexlib.com regex fits needs. and, of course, suggested in comments, please don't parse markup langugages regexen.
for example, site cited above, can find regex:
/^[-+]?\d+(\.\d+)?$/
with description: matches real number, optional decimal point , numbers after decimal, , optional positive (+) or negative (-) designation.
it whether want enclose regex in ^
, $
, or requirements have eg. whitespaces in front or behind numbers etc. note regex example gave matches (ie. validates) numbers, grab them, have care [+-]
signs.
Comments
Post a Comment