8 messages in net.php.lists.php-generalRe: [PHP] Re: Can someone help me bui...
FromSent OnAttachments
mwes...@sola.com.auMay 2, 2005 1:09 am 
Jason SweeneyMay 2, 2005 5:19 am 
Thomas BonhamMay 2, 2005 5:51 am 
mwes...@sola.com.auMay 2, 2005 4:12 pm 
Rory BrowneMay 2, 2005 4:30 pm 
Jochem MaasMay 2, 2005 5:06 pm 
Matthew Weier O'PhinneyMay 3, 2005 9:23 am 
Kim MadsenMay 4, 2005 6:03 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [PHP] Re: Can someone help me build a regular expression?Actions...
From:Jochem Maas (joc@iamjochem.com)
Date:May 2, 2005 5:06:41 pm
List:net.php.lists.php-general

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 free@yahoo.com