escape a string literal for use with regex?

2006-05-02 Thread David Purton
How can I escape a string literal easily for use as a regex with grep? e.g., Say I wanted to implement a procmail killfile, that might, say contain a mail subject line (dropped in with a mutt macro) like this: Re: OT: Politics [Was:Social Contract] (Hypothetical situation, of course...) Then

Re: escape a string literal for use with regex?

2006-05-02 Thread Roberto C. Sanchez
David Purton wrote: How can I escape a string literal easily for use as a regex with grep? e.g., Say I wanted to implement a procmail killfile, that might, say contain a mail subject line (dropped in with a mutt macro) like this: Re: OT: Politics [Was:Social Contract] (Hypothetical

Re: escape a string literal for use with regex?

2006-05-02 Thread David Purton
On Tue, May 02, 2006 at 03:01:02AM -0400, Roberto C. Sanchez wrote: David Purton wrote: How can I escape a string literal easily for use as a regex with grep? e.g., Say I wanted to implement a procmail killfile, that might, say contain a mail subject line (dropped in with a mutt

Re: escape a string literal for use with regex?

2006-05-02 Thread Jon Dowland
At 1146586566 past the epoch, David Purton wrote: How can I escape a string literal easily for use as a regex with grep? If you feed it through perl, you can enclose the suspect string with \Q and \E. Here's an excerpt from a perl script which I generate my procmail recipes with: $reexp

RE: escape a string literal for use with regex?

2006-05-02 Thread Roberts, Andy
David Purton wrote: I need something automatic though. I have no control on what formail returns. It just returns the subject as a string. I need to be able to search for that string in the killfile just using literals and not caring about regex. Can you not just use grep -F? To use your

Re: escape a string literal for use with regex?

2006-05-02 Thread David Purton
On Tue, May 02, 2006 at 11:09:30AM +0100, Jon Dowland wrote: At 1146586566 past the epoch, David Purton wrote: How can I escape a string literal easily for use as a regex with grep? If you feed it through perl, you can enclose the suspect string with \Q and \E. Here's an excerpt from a perl

Re: escape a string literal for use with regex?

2006-05-02 Thread Christopher Nelson
On Wed, May 03, 2006 at 09:34:19AM +0930, David Purton wrote: snip I ended up using fgrep, which if I had read the grep manual I would have found does what I want (Blush). This works well: # subject kill file SUBJECT=`formail -zxSubject:` :0: * ? fgrep -qx $SUBJECT

Re: escape a string literal for use with regex?

2006-05-02 Thread David Purton
On Tue, May 02, 2006 at 05:22:34PM -0700, Christopher Nelson wrote: On Wed, May 03, 2006 at 09:34:19AM +0930, David Purton wrote: snip I ended up using fgrep, which if I had read the grep manual I would have found does what I want (Blush). This works well: # subject kill file