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
What's this code line mean?
Moderator: General Moderators
-
camarosource
- Forum Commoner
- Posts: 77
- Joined: Sat Aug 03, 2002 10:43 pm
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
http://php.net/manual/en/pcre.pattern.syntax.php
and I also think it will accept the following string 2-12CAPHP123456
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.
Re: What's this code line mean?
i get the feeling i know the perl shorts better than the rest.
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
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 digitscamarosource wrote:if (preg_match ("/2\D\d\d\D[2-9|A]\w\d\d\d\d\d\d/", $vin))
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
it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will matchdelorian wrote:and I also think it will accept the following string 2-12CAPHP123456
Re: What's this code line mean?
I already know that m3rajk, user will already told me that, and I said that was my mistake, right...m3rajk wrote:it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will matchdelorian wrote:and I also think it will accept the following string 2-12CAPHP123456
Re: What's this code line mean?
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 fordelorian wrote:I already know that m3rajk, user will already told me that, and I said that was my mistake, right...m3rajk wrote:it wont match this. "HP123456" is the part that's the dviation form the pattern. on the other hand 2-12CAP123456 will matchdelorian wrote:and I also think it will accept the following string 2-12CAPHP123456