Page 1 of 1

What's this code line mean?

Posted: Tue Aug 19, 2003 11:26 am
by camarosource
if (preg_match ("/2\D\d\d\D[2-9|A]\w\d\d\d\d\d\d/", $vin))

I understand preg_match is used to match chars in the variable, in this case "$vin". But don't understand what exactly it's matching "/2\D\d\d\D[2-9|A]\w\d\d\d\d\d\d/"

Thanks

Posted: Tue Aug 19, 2003 2:17 pm
by delorian
I would say that's some ID-like. Maybe some account number (but not bank account). Here's something which will clear your mind ->

http://php.net/manual/en/pcre.pattern.syntax.php

and I also think it will accept the following string 2-12CAPHP123456

Posted: Tue Aug 19, 2003 9:46 pm
by camarosource
thanks..

Posted: Wed Aug 20, 2003 5:44 am
by will
delorian wrote:I would say that's some ID-like. Maybe some account number (but not bank account). Here's something which will clear your mind ->

http://php.net/manual/en/pcre.pattern.syntax.php

and I also think it will accept the following string 2-12CAPHP123456

well, close. \w matches a word character, not an actual word. from the link you provided..
A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place (see "Locale support" above). For example, in the "fr" (French) locale, some char- acter codes greater than 128 are used for accented letters, and these are matched by \w.

Posted: Wed Aug 20, 2003 9:10 am
by delorian
will wrote:well, close. \w matches a word character, not an actual word. from the link you provided..
Yea, you're right, my mistake.

Re: What's this code line mean?

Posted: Wed Aug 20, 2003 2:52 pm
by m3rajk
i get the feeling i know the perl shorts better than the rest.
camarosource wrote:if (preg_match ("/2\D\d\d\D[2-9|A]\w\d\d\d\d\d\d/", $vin))
take $vin and checks that it has a section (not necessarily the whole string, not necessarily the begining OR ending) that starts with the number two, followed by character that's not a digit, followed by two digits, followed by any non-digit, followed by a digit that's in the range 2-9 inclusive OR the letter A (and it has to be capitalized)followed by any word character followed by 6 digits

it could be switched to if (preg_match ("/2\D\d{2}\D[2-9|A]\w\d{6}/", $vin)) without any change

the perl shorts are:
\w any character in the following range: A-Za-z-0-9_
\W anything not in \w
\d any character in the rage: 0-9
\D anything not in \d
\s any "white space" character
\S anything not in \s
delorian wrote:and I also think it will accept the following string 2-12CAPHP123456
it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will match

Re: What's this code line mean?

Posted: Thu Aug 21, 2003 12:10 pm
by delorian
m3rajk wrote:
delorian wrote:and I also think it will accept the following string 2-12CAPHP123456
it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will match
I already know that m3rajk, user will already told me that, and I said that was my mistake, right... :D

Re: What's this code line mean?

Posted: Thu Aug 21, 2003 2:52 pm
by m3rajk
delorian wrote:
m3rajk wrote:
delorian wrote:and I also think it will accept the following string 2-12CAPHP123456
it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will match
I already know that m3rajk, user will already told me that, and I said that was my mistake, right... :D
i wasn't sure if you meant caphp as the word or php so i wasn't sure which you took it as, thats why i decided to mention where you go off the actual patten looked for