Reg python regexp

Youta TAKAOKA youta.t at gmail.com
Wed Mar 21 09:49:37 EDT 2018


sankarramanv,

It seems for me that this task does not need both python AND shell. Only
python does it, as well as only shell.

Of course, there can be some restrictions let you use both. (the real world
is filled up with such troublesome matters !)
If you *really* need to use `lgrep`, try `-f` option.
`lgrep -f` uses pattern as just a fixed text, not regexp.

2018年3月21日(水) 20:35 Rhodri James <rhodri at kynesim.co.uk>:

> On 21/03/18 10:44, sankarramanv at gmail.com wrote:
> > Hi,
> >
> > I have a requirement.
> >
> > cmd="cat <file>|grep -c 'if [ -t 1 ]; then mesg n 2>/dev/null; fi'"
> >
> > I need to escape only the square brackets in above variable since its
> not grepping without escaping the brackets.
>
> You need to escape the square brackets as you normally would for your
> shell, with backslashes I presume.  Then you need to escape the
> backslashes so they aren't interpreted specially by Python, with more
> backslashes.
>
> --
> Rhodri James *-* Kynesim Ltd
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list