using regex to select line matches

N

nadabadan

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
 
S

Steven M. O'Neill

nadabadan said:
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
}
 
G

Gunnar Hjalmarsson

nadabadan said:
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".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top