Brandon_R Posted August 10, 2009 Share Posted August 10, 2009 Hello guys i need a little bit of help with this. I need the regex for example - ULUS-12345 Broken down into 4 parts (UL) (US) (-) (12345) The first part can be either UL or UC The second part can be wither US or ES or JP The third part must be a dash The forth part must consist of 5 numbers. Thank You Brandon_R Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/ Share on other sites More sharing options...
nrg_alpha Posted August 10, 2009 Share Posted August 10, 2009 One possible pattern could be: #^U[LC](?:[uE]S|JP)-[0-9]{5}$# Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-895157 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 Nope not working. Keeps on getting an error Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-903729 Share on other sites More sharing options...
.josh Posted August 22, 2009 Share Posted August 22, 2009 Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-903732 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 Any fix guys? Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-903795 Share on other sites More sharing options...
nrg_alpha Posted August 22, 2009 Share Posted August 22, 2009 Well, given your initial post explanation, my pattern would satisfy this.. so either your explanation is incomplete / inaccurate, or there is more to the info than you have given. As CV is hinting, simply stating it isn't working doesn't help us at all. The only thing I can think of off the top of my head is to perhaps try removing the initial ^ and trailing $ character (as this checks from beginning of string to end of string). If the sample along the lines of ULUS-12345 is in the middle of a larger string, the pattern will fail. Please give us some complete sample strings so that we can see why it isn't working. Without much info to go by, it's rather difficult to troubleshoot, wouldn't you think? Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-903827 Share on other sites More sharing options...
.josh Posted August 22, 2009 Share Posted August 22, 2009 -Post the code in which you tried the pattern in -Post example content you're trying to match -Post what the actual error is For real, it continues to boggle my mind how many people lack the basic common sense to post more than "it doesn't work" Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-903972 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 /** * Verifies that the game region id is valid * * @param string numbers and/or letters * * @return */ function verify_game_region_id(&$game_region_id) { if (!preg_match('#^U[LC](?:[uE]S|JP)-[0-9]{5}$#', $game_region_id)); { return false; } } Basically i want it to match wither ULUS-12345 or UCUS-12345 or UCJS-12345. The last 5 digits must be numbers. Thanks for all your help so far guys Brandon_R Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904002 Share on other sites More sharing options...
nrg_alpha Posted August 22, 2009 Share Posted August 22, 2009 What does $game_region_id look like? Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904014 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 Basically its what users type in the form and i catch it with a post like $game_region_id = $_POST It looks like this ULUS-12345 or UCUS-12345 or UCJS-12345 Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904018 Share on other sites More sharing options...
nrg_alpha Posted August 22, 2009 Share Posted August 22, 2009 Basically its what users type in the form and i catch it with a post like $game_region_id = $_POST It looks like this ULUS-12345 or UCUS-12345 or UCJS-12345 Ok, so if it's in a post that users enter info from, then it's possible that this info could be part of a larger message? If so, try the initial regex pattern without ^ or $ if (!preg_match('#U[LC](?:[uE]S|JP)-[0-9]{5}#', $game_region_id)) By the way, looking at your previous snippet, I just noticed that you have a semicolon at the end of the if line.. You'll need to remove that (as I have done in this snippet I just provided). Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904029 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 this is all thats entered in the form for this field. I even have a maxlength = 10 just to make sure. Ill try the new regex. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904037 Share on other sites More sharing options...
thebadbad Posted August 22, 2009 Share Posted August 22, 2009 In that case you should have the ^ and $ in the pattern. Would help if you posted the code where you actually use your function. Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904043 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 Here is the code that runs the function: var $validfields = array( 'gamecodearchiveid' => array(TYPE_UINT, REQ_INCR, VF_METHOD, 'verify_nonzero'), 'gamecodearchivename' => array(TYPE_STR, REQ_YES, VF_METHOD, 'verify_gamecodearchivename'), 'gamecodearchiveregionid' => array(TYPE_STR, REQ_YES, VF_METHOD, 'verify_gamecodearchiveregionid'), 'gamecodearchiveregion' => array(TYPE_UINT, REQ_YES, VF_METHOD, 'verify_gamecodearchiveregion'), 'gamecodearchivecodes' => array(TYPE_STR, REQ_YES, VF_METHOD, 'verify_gamecodearchivecodes') ); as You can see its the 3rd 1 down that defines the function to verify the input then goes on to save. thats basically it I already posted the finction above. If the reges isnt working could you guys just give me 1 that checks (4 letters then a dash then 5 numbers)? Dont worry about the exact letters. Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904075 Share on other sites More sharing options...
.josh Posted August 22, 2009 Share Posted August 22, 2009 maybe try trimming it before the regex? Also, all your posts have shown it in capital letters. Is it supposed to be a case-sensitive match? If not, then you need to use the 'i' modifier Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904078 Share on other sites More sharing options...
Brandon_R Posted August 22, 2009 Author Share Posted August 22, 2009 I cant belive i didnt see this. if (!preg_match('#^U[LC](?:[uE]S|JP)-[0-9]{5}$#', $game_region_id)); <--- look at the ';' that doesnt belong there. Thanks anyways guys, wasnt the regex Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904184 Share on other sites More sharing options...
nrg_alpha Posted August 23, 2009 Share Posted August 23, 2009 I cant belive i didnt see this. if (!preg_match('#^U[LC](?:[uE]S|JP)-[0-9]{5}$#', $game_region_id)); <--- look at the ';' that doesnt belong there. Thanks anyways guys, wasnt the regex Yes, I know.. hence from my previous post: By the way, looking at your previous snippet, I just noticed that you have a semicolon at the end of the if line.. You'll need to remove that... Please don't forget to mark this thread as solved. Quote Link to comment https://forums.phpfreaks.com/topic/169685-solved-what-is-the-regex-to-match-this-code/#findComment-904191 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.