문제

My string will be like following

'popular-game-show-identifier-popular-games-mv-11'

In above string I want to check,

  1. Each word must followed by hyphen, except first word.
  2. In between the string identifier word must exist.
  3. End of the string must contain -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.

도움이 되었습니까?

해결책

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+))$/
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top