On 3/20/06, stu meacham <[EMAIL PROTECTED]> wrote: > I would like to modify a file 'in place' at the command line with regexes. > The file changes daily and is messy. Can one negate a regex itself as > opposed to a class of regular expressions? If I could remove everything but > that selected by m/\d{2}\t\d{2}\t\d{2}/g life would be better as I know it. > Thanx > > --
Stu, The short answer is "not really," but it depends on your data, and what, exactly, you want to do. Do you want to remove lines that don't match? Do you want to delete just the parts of the line that don't match? Is your data delimited in some way and you want to remove all fields but one? There are several (at least) ways to approach this, depending on the situation. Here are some thoughts to get you started, though: in list context, m// returns an array of capturing paren matches, so something like: @matched = /(\d{2}\t\d{2}\t\d{2})/g; print "@matched\n"; might work for you. You could also try something like: s/.*?(\d{2}\t\d{2}\t\d{2}).*?(?!\d{2}\t\d{2}\t\d{2})/$1/g look for (?!) and "zero-width negative lookahead" in perlre. And of course if your data can be conveniently split into fileds, check out the -a flag in perlrun and grep() in perlfunc. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!