Frosty Posted November 11, 2013 Share Posted November 11, 2013 (edited) 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-]+/ Edited November 11, 2013 by Frosty Quote Link to comment https://forums.phpfreaks.com/topic/283822-regex-targeting-urls-with-dashes-only/ Share on other sites More sharing options...
Solution requinix Posted November 11, 2013 Solution 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". Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.