SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Regular expression help needed.

    Hello Guys,

    I need your help.
    I am having the information of the user.In this each user submits 6 documents.
    The name of documents are like

    username_A.pdf
    username_B.pdf
    username_A.jpg
    username_B.jpg
    username_thumb.jpg
    username.doc

    Now I want only username_A.jpg.The values for extensions are jpg,jpeg,JPG,JPEG.
    So could any one help me please how to extract say _A.jpg from all the 6 documents.

    I am using the following reg. expression.But it also matches for pdf.
    PHP Code:
    preg_match("/_A\.[jpg|JPG|jpeg|JPEG]/",$file)
    //also tried for
    if(preg_match("/_A\.[(jpg)|(JPG)|(jpeg)|(JPEG)]/",$file)) 
    Your help will be appriciated.
    Thanks,
    Barbara

  2. #2
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you need case insensitive?

    PHP Code:
    <?php
    // The "i" after the pattern delimiter indicates a case-insensitive search
    if (preg_match("/php/i""PHP is the web scripting language of choice.")) {
        echo 
    "A match was found.";
    } else {
        echo 
    "A match was not found.";
    }
    ?>
    Taken from: http://www.php.net/manual/en/function.preg-match.php
    Sry its kind of out of context
    <3php && SitePoint ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Waroona, WA, Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is by far the best resource I have found on Reg Exps, hopefully it will be of some use to you

    http://weblogtoolscollection.com/regex/regex.php

  4. #4
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks t0WL337 and ozPATT
    I know that "i" is case-insensitive.

    This is my php code
    PHP Code:
    $file="Myfile_A_A.jpg";
    if(
    preg_match("/_A\.[(jpg)|(JPG)|(jpeg)|(JPEG)]/",$file))
    {
        echo 
    "Matched";
    }
    else
    {
        echo 
    "Not Matched";

    The o/p = Matched.

    But if I change the extension say .pdf.It is also giving me the o/p as "Matched".
    which i don't want.I want only extensions having jpg images.

    Please help me.
    Barbara

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    if(preg_match("/_A\.(jpg|jpeg)$/i",$file))
    Saul

  6. #6
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks php_daemon,

    It worked.
    Cheers.
    Barbara


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •