spitfire1945 Posted February 19, 2009 Share Posted February 19, 2009 Hey folks. I am a little weak in the Regex field I just need to validate google adsense publisher ids which come in a "pub-xxxxxxxxxxxxxxxx" (16 x's where all x's are numbers) format. just the reg expression would be nice. Ill throw my guesses down though: #$"pub-"^[0-9]{16}$# ??? am i even close? Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/ Share on other sites More sharing options...
effigy Posted February 19, 2009 Share Posted February 19, 2009 /\Apub-\d{16}\z/ Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-766569 Share on other sites More sharing options...
spitfire1945 Posted February 19, 2009 Author Share Posted February 19, 2009 /\Apub-\d{16}\z/ thank you sir Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-766629 Share on other sites More sharing options...
nrg_alpha Posted February 19, 2009 Share Posted February 19, 2009 Why guess when you can simply try it out? Testing / experimenting with things can be quite interesting as well as admittedly sometimes frustrating (not to mention, most importantly, educational). Taking self initiatives can go a long way towards independence. Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-766632 Share on other sites More sharing options...
.josh Posted February 20, 2009 Share Posted February 20, 2009 I think he probably did try it and failed and that's why he was here, and he was simply wondering if his current attempt was even on the right track. Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-766699 Share on other sites More sharing options...
nrg_alpha Posted February 20, 2009 Share Posted February 20, 2009 Maybe it was the wording.. throwing guesses. Perhaps I misinterpreted. Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-766714 Share on other sites More sharing options...
spitfire1945 Posted February 21, 2009 Author Share Posted February 21, 2009 no i just simply fail at regex. It is probably the easiest and most robust concept but i cannot get it into my head. Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-767694 Share on other sites More sharing options...
nrg_alpha Posted February 21, 2009 Share Posted February 21, 2009 no i just simply fail at regex. It is probably the easiest and most robust concept but i cannot get it into my head. Regex isn't necessarily hard, per say, but just slightly tricky at first. It's the rules of engagement that can kick your @$$ if you don't know what you are doing. You can have a look at the resources page as well as this tutorial from Darkwater. And of course, there is also this site as well as my favorite, this book. Sorry for the link bombardment... there are plenty of options. As for regex itself, its just a matter of starting simple and building up. Overall, it's not hard, and quite nice to use once you really get the hang of it (almost addictive actually). I would need to attend a PCRE Anonymous meeting if there ever was such a thing... Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-767821 Share on other sites More sharing options...
spitfire1945 Posted February 22, 2009 Author Share Posted February 22, 2009 no i just simply fail at regex. It is probably the easiest and most robust concept but i cannot get it into my head. Regex isn't necessarily hard, per say, but just slightly tricky at first. It's the rules of engagement that can kick your @$$ if you don't know what you are doing. You can have a look at the resources page as well as this tutorial from Darkwater. And of course, there is also this site as well as my favorite, this book. Sorry for the link bombardment... there are plenty of options. As for regex itself, its just a matter of starting simple and building up. Overall, it's not hard, and quite nice to use once you really get the hang of it (almost addictive actually). I would need to attend a PCRE Anonymous meeting if there ever was such a thing... Thanks alpha! I did look at those. I did have some success today when i was running the preg_match command for alphanumeric and underscore only strings. preg_match("/[a-zA-Z0-9_]$/", $var) (and then i looked at ur signature and lol'ed) it worked, i think i could have also used /w if i am not wrong. Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-768269 Share on other sites More sharing options...
nrg_alpha Posted February 22, 2009 Share Posted February 22, 2009 preg_match("/[a-zA-Z0-9_]$/", $var) Alternatively, you could have done: '/[a-z0-9_]$/i' <--------- the i modifier after the closing delimiter matches / captures case insensitive alpha characters -or- '/\w$/' <----------- the \w is a short hand character class for [a-zA-Z0-9_] Quote Link to comment https://forums.phpfreaks.com/topic/146017-regex-for-pub-id/#findComment-768475 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.