|
Posted by Jochem Maas on 05/03/05 03:07
Rory Browne wrote:
>>You mite try this. I know that this work with perl.
mites byte.
>>
>>=~ m/^[0-9][A-Z][a-z]{2-3} \.[0-9]+$/
>
>
> I'm not sure what the initial m does(I'm not a perl person), but the
> rest of the regex matches as follows.
>
> A string whose first character is a digit between 0 and 9. This is
> followed by an Upper case letter, and then two or three lower case
> letters. All that is followed by a period(or dot), after which may be
er?
> a single-digit number, but nothing else.
>
> It matches the following:
>
> 1Abc.2
> 1Abcd.2
> 1Abc.
> 1Abcd.
>
try this and see if that is correct:
php -r '
$a = array(
"gnaglreg1Abc.2ewfergwrgbt","1Abc.2","1Abcd.2","1Abc.","1Abcd.","1Abcd .2","1Abcd .2",
"1Abcd.22","1Abcd .22","1Abcd .22","1Abcd.232");
foreach ($a as $s) {
echo "\ntrying:\t\t\"$s\":\n--\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2-3} \.[0-9]+$/", "..!!GOTCHA1!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3} \.[0-9]+$/", "..!!GOTCHA2!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3} \.[0-9]?$/", "..!!GOTCHA3!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}\.[0-9]+$/", "..!!GOTCHA4!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}\.[0-9]?$/", "..!!GOTCHA5!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}[ ]?\.[0-9]+$/", "..!!GOTCHA6!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}[ ]{1,}\.[0-9]+$/", "..!!GOTCHA7!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}[ ]?\.[0-9]?$/", "..!!GOTCHA8!!..", $s),"\n";
echo preg_replace("/^[0-9][A-Z][a-z]{2,3}[ ]{1,}\.[0-9]?$/", "..!!GOTCHA9!!..", $s),"\n";
echo "---\n";
}
'
>
>
>>I'm still very new to this. But I'm trying to help.
run the above code, examine the output (if you are going to do it in a browser echo out
some <pre> tags). hopefully the 9 variations will give you a little bit of insight.
read every page here: http://nl2.php.net/manual/en/ref.pcre.php - its a good
primer on regexp.
don't worry if you don't understand half of it. often things become
clear as you continue to read/experiment :-)
>>Thomas
>>freeswimfreak@yahoo.com
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
[Back to original message]
|