Regular expressions patterns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ogo796
    New Member
    • Jan 2008
    • 44

    Regular expressions patterns

    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.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    What have you tried so far?

    Comment

    • dlite922
      Recognized Expert Top Contributor
      • Dec 2007
      • 1586

      #3
      Originally posted by ogo796
      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:

      Code:
      if(preg_match_all("/.+\[[0-9]{4}\]\sNAME\s[0-9]{1}/",$yourVar,$matches))
      {
         echo "I found These:\n";
         print_r($matches);
      }
      else
      {
         echo "Didn't find anything";
      }
      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

      Comment

      Working...