Reputation: 1689
My string will be like following
'popular-game-show-identifier-popular-games-mv-11'
In above string I want to check,
identifier
word must exist.-mv-
appended to digit.To check 1, 3 following regular expression working fine.
/[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*(-mv-(\d+))$/
Now I want to check 2 also, for that I'm modified above expression to
/[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*(\-identifier\-)(\-[a-zA-Z0-9]+)*(-mv-(\d+))$/
preg_match()
always returning 0
if I use above regular expression to check all 3 conditions. I'm not getting where I've did wrong.
Upvotes: 1
Views: 64
Reputation: 1856
You have "extra" hyphen
/[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*(\-identifier\-)(\-[a-zA-Z0-9]+)*(-mv-(\d+))$/
Should be
/[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*(\-identifier)(\-[a-zA-Z0-9]+)*(-mv-(\d+))$/
Upvotes: 3