Professional Web Applications Themes

A problem of pattern matching - PERL Beginners

I wanna match a specific pattern using grep(). My pattern has two parts: 1. exclude "." or ".." (to exclude the current and parent directory in unix) 2. the file type is jpg. The first pattern I am using is !/^\.\.?$/ The second is /\.jpg$/i How to combine them together? using two greps or a single one? thanks a lot! eruisi 10/09/2004 20:31:25...

  1. #1

    Default A problem of pattern matching

    I wanna match a specific pattern using grep().
    My pattern has two parts:

    1. exclude "." or ".." (to exclude the current and parent
    directory in unix)
    2. the file type is jpg.

    The first pattern I am using is !/^\.\.?$/
    The second is /\.jpg$/i

    How to combine them together? using two greps or a single
    one?

    thanks a lot!

    eruisi
    10/09/2004
    20:31:25

    Teng Guest

  2. #2

    Default Re: A problem of pattern matching

    Teng Wang wrote: 

    You don't need both patterns because a file name *CANNOT* match both of those
    patterns at the same time. Just use /\.jpg$/i.


    John
    --
    use Perl;
    program
    fulfillment
    John Guest

  3. #3

    Default Re: A problem of pattern matching

    On Oct 9, 2004, at 7:35 PM, Teng Wang wrote:
     

    Disclaimer: beginner helping beginner here! ;)

    Why do you need to explicitly exclude "." and ".."? They won't match
    /\.jpg$/i

    I ran this from my Unix shell (after cd'ing to the dir I was interested
    in), to test the pattern, and it printed what you seem to be looking
    for....

    ls -a | perl -n -e 'print if /\.jpg$/i;'

    Chap

    Chap Guest

Similar Threads

  1. pattern matching
    By Tad McClellan in forum PERL Beginners
    Replies: 30
    Last Post: June 23rd, 07:42 PM
  2. Help with pattern matching
    By A in forum PERL Beginners
    Replies: 2
    Last Post: April 4th, 08:52 PM
  3. Pattern matching problem
    By Henry in forum PERL Beginners
    Replies: 20
    Last Post: February 26th, 06:51 PM
  4. file path pattern matching problem.
    By Ben Crane in forum PERL Beginners
    Replies: 4
    Last Post: December 10th, 08:30 PM
  5. Help; Pattern Matching
    By MJS in forum PERL Miscellaneous
    Replies: 6
    Last Post: September 27th, 01:22 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139