How do I use a regular expression to match a number as an integer?

When I match a number using a regular expression I get it as a string:

?> 'TestingSubject2981'.match /\d+$/
=> #<MatchData "2981">

Is it somehow possible to get the number as an integer without some to_is?

Answers


The issue is that regular expressions only work on strings, not on other data types.

A regex has patterns to match numbers, but those still only find the characters that represent the number, not the binary values that we'd use for math. Once the engine returns the matches, they're still characters, so we have to use to_i to convert them to their binary representations.

MMM-kay?


Need Your Help

Popover view from UICollectionView causing unwind

ios uicollectionview uipopovercontroller

I have a matrix of data (players) displayed in a UICollectionView. I want details on a player to display in a popover view when the user touches a cell. I asked this question earlier and got it to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.