Frosty Posted November 11, 2013 Share Posted November 11, 2013 I'm hoping to finish a regex that I've been trying to craft, and would like some advice as I've hit a roadblock . So I have a whole list of urls. I need to only capture 'seo friendly' (typically article/post titles) urls with at least one dash, like: http://thepigeonnest.com:80/passenger-pigeons-ectopistes-migratorius/ http://thepigeonnest.com/pigeon-lover-mike-tyson-to-star-in-pigeon-reality-show/ But, my regex also captures sub-folders without a dash like: http://pinkstripedpig.com/contact/ My regex so far is thus: http://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}(/|:80/)[a-z0-9-]+/ Link to comment https://forums.phpfreaks.com/topic/283822-regex-targeting-urls-with-dashes-only/ Share on other sites More sharing options...
requinix Posted November 11, 2013 Share Posted November 11, 2013 Turn [a-z0-9-]+which says "at least one letter or number or hyphen", into [a-z0-9]+-[a-z0-9-]+which says "at least one letter or number, then a hyphen, then more letters or numbers or hyphens". Link to comment https://forums.phpfreaks.com/topic/283822-regex-targeting-urls-with-dashes-only/#findComment-1457940 Share on other sites More sharing options...
Frosty Posted November 11, 2013 Author Share Posted November 11, 2013 Wow, that's much more eloquent than the one I just come up with: http://([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}(/|:80/)((\w)+(-)+)+\w+/ Many thanks! Issue resolved. Link to comment https://forums.phpfreaks.com/topic/283822-regex-targeting-urls-with-dashes-only/#findComment-1457944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.