jordanwb Posted September 14, 2007 Share Posted September 14, 2007 A particular value is passed through GET in the particular format: (a-z)-(0-9), Example: nid-7 eid-24 Would this pattern work: ^([a-z]\-[0-9])*$ Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/ Share on other sites More sharing options...
effigy Posted September 14, 2007 Share Posted September 14, 2007 No; without a quantifier a character class matches only one character. Also, there is no need to escape the hyphen or place a quantifier on the grouping. What is the maximum number of letters and digits you're expecting? Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348045 Share on other sites More sharing options...
jordanwb Posted September 14, 2007 Author Share Posted September 14, 2007 Really a maximum of 10 letters and there may be a unlimited number of numbers. Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348366 Share on other sites More sharing options...
effigy Posted September 14, 2007 Share Posted September 14, 2007 This will require one to ten lowercase letters, followed by a hyphen, followed by one or more digits: /\A[a-z]{1,10}-\d+\z/ Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348381 Share on other sites More sharing options...
jordanwb Posted September 14, 2007 Author Share Posted September 14, 2007 Okay thanks. Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348421 Share on other sites More sharing options...
jordanwb Posted September 14, 2007 Author Share Posted September 14, 2007 I tried it and it didn't work if (!eregi ('/\A[a-z]{1,10}-\d+\z/', 'nid-1')) { print "Failed"; } it outputed Failed everytime. I could try using explode, split the 'nid' and the number apart, then compare. Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348531 Share on other sites More sharing options...
effigy Posted September 14, 2007 Share Posted September 14, 2007 You need to use preg_match; it's a PCRE pattern, not an EREG pattern. Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348541 Share on other sites More sharing options...
jordanwb Posted September 14, 2007 Author Share Posted September 14, 2007 I was not aware there was a difference. Now I do. It works, Thanks. Link to comment https://forums.phpfreaks.com/topic/69263-solved-correct-regex-pattern-for-purpose/#findComment-348668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.