regular expression patterns

Reply

Join Date: Aug 2008
Posts: 14
Reputation: cosby is an unknown quantity at this point 
Solved Threads: 0
cosby cosby is offline Offline
Newbie Poster

regular expression patterns

 
0
  #1
Aug 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 828
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: regular expression patterns

 
0
  #2
Aug 14th, 2008
  1. (\[[0-9]{4}\] name [0-9];)$
Last edited by pritaeas; Aug 14th, 2008 at 7:20 am.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 14
Reputation: cosby is an unknown quantity at this point 
Solved Threads: 0
cosby cosby is offline Offline
Newbie Poster

Re: regular expression patterns

 
0
  #3
Aug 14th, 2008
Originally Posted by pritaeas View Post
  1. (\[[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['path'];

$jaar=$_POST['years'];
$name= $_POST['Name'];
echo $court."<br />";
$number=$_POST['Number'];
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;

}
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 828
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 136
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: regular expression patterns

 
0
  #4
Aug 14th, 2008
Since the dat ais fixed, use:

  1. $preg = "(\[$year\] $name $number;)\$";
  2. $foundAMatch = preg_match("/$preg/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE);
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 14
Reputation: cosby is an unknown quantity at this point 
Solved Threads: 0
cosby cosby is offline Offline
Newbie Poster

Re: regular expression patterns

 
0
  #5
Aug 14th, 2008
Thanks very much it works fine.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC