By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Regular expressions patterns

P: 44
hi everyone

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

"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.
Aug 14 '08 #1
Share this Question
Share on Google+
2 Replies


Atli
Expert 5K+
P: 5,058
Hi.

What have you tried so far?
Aug 15 '08 #2

dlite922
Expert 100+
P: 1,584
hi everyone

i want the regular expression patterns that match this : [2005] NAME 9 ; or [2004] NAME 8; on the above strings.
Please tell us what you wanted to match.

Do you want it to match only 2004 and 2005? all years, any year? years greater than a particular year?

also

what does "NAME" mean? is it just the exact string all capital? is it any four letter word in any case (upper or lower)? can it be only certain names?

again the digit

is it a digit range? how large is the range? 1 to 9 or 0 to infinity?

These are the type of questions you should be answering when you're telling us a pattern to match.

here's an example:

Expand|Select|Wrap|Line Numbers
  1. if(preg_match_all("/.+\[[0-9]{4}\]\sNAME\s[0-9]{1}/",$yourVar,$matches))
  2. {
  3.    echo "I found These:\n";
  4.    print_r($matches);
  5. }
  6. else
  7. {
  8.    echo "Didn't find anything";
  9. }
  10.  
That will match any line that has any characters in front followed by a whitespace character. Followed by a four digit number in brackets, then a space followed by the string "NAME", another space, and finally a 1 digit number.



Let us know,



Dan
Aug 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.