user798719
user798719

Reputation: 9869

Regex to grab a number from within a string

I would like to grab a number from a string.

The string is: "responseID: 1 is the return value";

Sometimes the number could be 1, or 3, 300, 3000...

I am trying to do this in objective C for the iphone.

I've tried NSPredicate and NSRegularExpression, but I can not seem to get the right regex to start with.

I tried "*[0-9]+*";

Does this return the "1" , "300" or whatever number to me when I call the regex?

Thank you!

Upvotes: 1

Views: 83

Answers (2)

user798719
user798719

Reputation: 9869

Sorry, I was able to search again and found exactly what I was looking for: see this: Objective C: How to grab a number after a sub string from string

Upvotes: 0

Qiau
Qiau

Reputation: 6175

\d+ should match 1 or more digits.

Upvotes: 2

Related Questions