user3746428 user3746428 - 1 year ago 64
iOS Question

Get app's ID number from iTunes URL string

I need to find a way to parse an app's ID number from an iTunes URL. For example, this URL -

Would give me this - 1021402097

I was considering different ways to do this with string splitting and such, but they all seem kind of hacky. I suppose I could just split the string after 'id' and end the split after 10 digits, but there's a risk that IDs could be increased to 11 digits in the future.

Anyone have a better idea using regex or something?


If you can make the following assumptions:

  • The id will only contain digits.
  • The number of digits, which currently is 10, will only grow.
  • In the url, the id... part contains the id.

Then, you can use a simple regex such as this: id([\d]{10,}), in which your id will be captured in group 1. Working example: