regex - PHP Regular Expression match anything except forward slash -
i'm going have 2 different sets of urls
/marketplace/producer/123-producer-name /marketplace/producer/123-producer-name/5-genre/500-max-price/0-added/newest/1-page
i know regular look second, first 1 i'm finding tricky. i'm trying match expression, want create sure doesn't match sec 1 well. i'm using following;
/\/marketplace\/producer\/([0-9]+)\-[^\/]/
my logic @ end beingness match every character except forwards slash, mean it's s possible match sec one. when test it, returns true forwards slash. doing wrong?
do this:
/^\/marketplace\/producer\/([0-9]+)-[^\/]+$/
your regex searches string starting with / followed marketplace/producer/ followed 1 or more digits followed - followed 1 or more characters not / , ends there.
i think problem there no anchoring character , matched substring of input also. missed + makes regex engine single non-forwardslash character.
php regex
No comments:
Post a Comment