URLPatterns Regex Help

I am trying to fix a bug in my ServiceInfo.plist file that is causing some problems. I've discovered some new URLs that aren't getting a match. 

 

Here are some example of normal episode URLS:

http://www.crunchyroll.com/[series_name]/episode-[episode_number]-[episode_name_separated_by_dashes]-[episode_id]




 

With those URLs in mind, Sander came up with the following regex to match URLs for my service:

 

^http://www.crunchyroll.com/[^/]+/episode\-\d+\-

 

Since then i've discovered some new URLs (preview videos, not actual full length episodes) being passed that don't match the above regex. These are the URLs causing my URL service problems:

 

http://www.crunchyroll.com/[series_name]/[series_name]-pv-[episode_number]-[episode_id]


http://www.crunchyroll.com/blast-of-tempest/blast-of-tempest-pv-1-612047

 

As i'm terrible at regex, i'm having a bit of trouble coming up with a regex that matches the above URLs. Here is my best guess:

 

^http://www.crunchyroll.com/[^/]+/.+pv\-\d+\-

 

Any help would be appreciated! 

 

Edit: To clarify, the above string does work, but i'm not sure if it's correct. I just want to make sure i'm not casting the net too wide and matching URLs that aren't exactly what i need. 

That looks fine to me, although I might tweak it a little:

^http://www.crunchyroll.com/[^/]+/.+?\-pv\-\d+\-\d+

I haven't tested this but in theory, the additions will do a few things.

1.) Adding the '?' after the '.+' makes it less "greedy" so it's less likely to match stuff that it shouldn't.

2.) Adding the '\-' before the 'pv' to match the one that follows it, insures that the matches will always include '-pv-' and won't incorrectly match edge cases where there might be a pv in the title or something wacky like that.

3.) Adding the last '\d+' should make sure that the url contains both the episode number and the episode id. It should help avoid situations where malformed urls provide the episode number but not the id which may (or may not) be problematic.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.