using regex to select line matches

Discussion in 'Perl Misc' started by nadabadan, Jun 15, 2007.

  1. nadabadan

    nadabadan Guest

    Hi,
    How do you select all lines that don't start with a particular
    word? For example,

    ^[^d].*$

    selects all lines that doesn't start with the letter d. But how I
    select all lines that doesn't start with the word "date". I tried
    ^[^date].*$ but this selects all lines that doesn't start with d, a,
    t or e.

    - Nada
     
    nadabadan, Jun 15, 2007
    #1
    1. Advertising

  2. nadabadan <> wrote:
    >Hi,
    > How do you select all lines that don't start with a particular
    >word? For example,
    >
    >^[^d].*$
    >
    >selects all lines that doesn't start with the letter d. But how I
    >select all lines that doesn't start with the word "date". I tried
    >^[^date].*$ but this selects all lines that doesn't start with d, a,
    >t or e.


    Like this?

    while (<>) {
    next if /^date/;
    #do other stuff
    }

    --
    Steven O'Neill
    Brooklyn, NY http://www.panix.com/~steveo
     
    Steven M. O'Neill, Jun 15, 2007
    #2
    1. Advertising

  3. nadabadan wrote:
    > How do you select all lines that don't start with a particular
    > word? For example,
    >
    > ^[^d].*$
    >
    > selects all lines that doesn't start with the letter d. But how I
    > select all lines that doesn't start with the word "date". I tried
    > ^[^date].*$ but this selects all lines that doesn't start with d, a,
    > t or e.


    For most practical purposes, Steven's solutions is probably sufficient.
    This is a regex that may be a more direct answer to your question:

    /^(?!date)/

    Please read about "Extended Patterns" in "perldoc perlre".

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jun 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan Bour

    Extracting matches from Regex.Split

    Stephan Bour, Oct 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,568
    Stephan Bour
    Oct 30, 2003
  2. darrel
    Replies:
    1
    Views:
    802
    Blair Bonnett
    Jan 3, 2005
  3. Replies:
    4
    Views:
    1,592
  4. Replies:
    3
    Views:
    1,566
  5. Spike Grobstein

    accessing all matches using regex

    Spike Grobstein, Aug 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    165
    Spike Grobstein
    Aug 6, 2007
Loading...

Share This Page