phpknight Posted August 20, 2007 Share Posted August 20, 2007 Hi, I am new the regex part of PHP and am trying to get a simple regex working with a set of four to six alphanumeric characters. This works: ^([^b]{4,6}) -- 5-6 characters--not b but once I do this: ^([:alnum:]{4,6}) it does not work. I've also tried doubling the brackets around alnum. I know I am missing something simple. I would appreciate some help. Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/ Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 i think you want this $data = "test"; if (preg_match('/^[a-z0-9]{4,6}$/i', $data)) { # Successful match } else { # Match attempt failed } or $data = "test"; if (eregi('^[a-z0-9]{4,6}$', $data)) { # Successful match } else { # Match attempt failed } $data = "test"; //works $data = "testing"; //fails $data = "tst"; //fails Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328846 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 So, is [:alnum:] not allowed, or is it the $ at the end that I am missing? What is the difference between the one with /i and the one without it? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328859 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 persaonlly i keep away from [:alnum:] personal choice.. The ^ means starts with and the $ means ends with so the whole string is from 4 to 6 chars the /i or eregi, means case insensitive.. so only a-z needed not a-zA-z. make sense ? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328870 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 Yes, that makes sense. I'll be sure to let you know if this helps me out. In fact, I think you answered another question of mine today, to thanks! Also, if you do know the alnum stuff, please post that as well. Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328913 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 a [:alnum:] version <?php $data = "test"; if (eregi('^[[:alnum:]]{4,6}$', $data)) { # Successful match } else { # Match attempt failed } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328934 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 Weird. I am using Regex Coach along with .htaccess to test these. If I do anything like alnum, it fails. But if I do this: ^[a-zA-Z0-9]{4,6} it works. What is the deal? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-328977 Share on other sites More sharing options...
effigy Posted August 20, 2007 Share Posted August 20, 2007 .htaccess means mod_rewrite, which uses PCRE. PCRE does not support that syntax. Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329022 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 Are you serious? I am reading the definitive guide to mod rewrite, and this is in there. I guess that would explain it, though! Can you give me a definitive link to what works in PCRE? ??? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329053 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 ~cougths~ http://www.pcre.org/ http://uk2.php.net/pcre Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329056 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 If you search for POSIX CHARACTER CLASSES on this page: http://www.pcre.org/pcre.txt it has alnum! What gives? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329070 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 can you post the mod_rewrite Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329088 Share on other sites More sharing options...
effigy Posted August 20, 2007 Share Posted August 20, 2007 From the mod_rewrite docs: Pattern is a perl compatible regular expression. For more information about regular expressions, have a look at the perl regular expression manpage ("perldoc perlre"). ...which points directly to Perl's regular expressions--not a "compatible" version. There is either a mix-up in terminology, or a more flexible definition of compatible involved. Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329093 Share on other sites More sharing options...
phpknight Posted August 20, 2007 Author Share Posted August 20, 2007 Okay. Somebody just told me that apache 1.3.37 does not support this notation, only Apache 2. Does that sound right to anybody? Quote Link to comment https://forums.phpfreaks.com/topic/65761-syntax-question/#findComment-329110 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.