hi everyone

can anyone help me with the php pattern that search the following string and get relevent pattern.

"2004_8.rtf" (November) S v Mimi(000/00) [2004] NAME 8;
"2005_9.rtf" (November) S v Mimi(000/01) [2005] NAME 9;

i want the regular expression patterns that match this : [2005] NAME 9 ; or [2004] NAME 8; on the above strings.

(\[[0-9]{4}\] name [0-9];)$

Thanks it work but it match everything on the text file.and i have a different names i want to match a specific name line with the data posted from the form.i have different year ,name and number

the data posted by the user look like the one

$jaar = $_POST[year];
$name = $_POST[name];
number = $_POST[number];
look at my code maybe you will have a clear picture of what i am trying to do.
$q=$_POST;

$jaar=$_POST;
$name= $_POST;
echo $court."<br />";
$number=$_POST;
echo $mnc."<br />";
$toSearch = "[".$jaar."]"." "$name." ".$number;
echo $toSearch."<br />";

$file =$q."Registry.txt";

$lines = file($file);

$count;
$lineNumbers;

if ($lines)

{

foreach($lines as $lineNumber)

{
$lineNumbers++;

$foundAMatch = preg_match("/$toSearch/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE);

if ($foundAMatch > 0)

{
echo $foundAMatch."<br />";

$found = $matches[0][0];

$count=$lineNumber;
echo $lineNumber."<br />";
write($lineNumbers,$lineNumber);

}

}


}

else

{

$line="no file/folder found";

echo $line;

}

Since the dat ais fixed, use:

$preg = "(\[$year\] $name $number;)\$";
$foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE);

Thanks very much it works fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.