Reputation: 25348
I need to select a small portion of a string.
Here's an example string: http://itunes.apple.com/app/eyelashes/id564783832?uo=5
I need: 564783832
A couple of things to keep in mind:
id
(ie. id564783832
)?uo=5
following the number (and it could be other parameters besides uo
)id
will have similar formatting (same # of slashes, but text will be different)This will ultimately be implemented with Ruby.
Upvotes: 0
Views: 89
Reputation: 61148
You can match some sequence of digits preceded by "id" - this assumes that those are the only sequence of digits preceded by "id":
(?<=id)\d++
A test case in Java:
public static void main(String[] args) {
String input = "http://itunes.apple.com/app/eyelashes/id564783832?uo=5";
Pattern pattern = Pattern.compile("(?<=id)\\d++");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
Output
564783832
Upvotes: 0
Reputation: 195059
without knowing your language/tool, just assume look behind was supported.
'(?<=id)\d+'
Upvotes: 2