Re: Reg python regexp

2018-03-21 Thread Youta TAKAOKA
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` opt

Re: Reg python regexp

2018-03-21 Thread Rhodri James
On 21/03/18 10:44, sankarram...@gmail.com wrote: Hi, I have a requirement. cmd="cat |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 a

Re: Reg python regexp

2018-03-21 Thread Chris Angelico
On Wed, Mar 21, 2018 at 9:44 PM, wrote: > Hi, > > I have a requirement. > > cmd="cat |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. > > Please help. You're putting this

Re: Reg python regexp

2018-03-21 Thread Paul Moore
Hi, You don't need a regexp for this, the "replace" method on a string will do what you want: >>> s = 'this is a [string' >>> print(s.replace('[', '\\[')) this is a \[string Paul On 21 March 2018 at 10:44, wrote: > Hi, > > I have a requirement. > > cmd="cat |grep -c 'if [ -t 1 ]; then mesg n

Reg python regexp

2018-03-21 Thread sankarramanv
Hi, I have a requirement. cmd="cat |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. Please help. Thanks. -- https://mail.python.org/mailman/listinfo/python-list

Re: Python regexp exclude problem

2011-06-01 Thread MRAB
On 01/06/2011 15:20, Lutfi Oduncuoglu wrote: Hello, I am trying to write a script for adding ip address to a list. Those ip addresses coming thorough from our edge router. I have a line in may script like if any(s not in z2 for s in('144.122.','188.38','193.140.99.2','213.161.144.166','

Re: Python regexp exclude problem

2011-06-01 Thread Christian Heimes
Am 01.06.2011 16:20, schrieb Lutfi Oduncuoglu: > Hello, > > I am trying to write a script for adding ip address to a list. Those ip > addresses coming thorough from our edge router. > I have a line in may script like > > if any(s not in z2 for s > in('144.122.','188.38','193.140.99.2','213

Python regexp exclude problem

2011-06-01 Thread Lutfi Oduncuoglu
Hello, I am trying to write a script for adding ip address to a list. Those ip addresses coming thorough from our edge router. I have a line in may script like if any(s not in z2 for s in('144.122.','188.38','193.140.99.2','213.161.144.166','92.45.88.242')): os.system(" echo " +z

Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-29 Thread conan
Thank you Paul. Since the only thing i'm doing is extracting this fields, and have no plans to include other stuff, a regexp is fine. However i will take into account 'pyparsing' when i need to do more complex parsing. As you can see in the example i send, i was trying to get info from a glade fi

Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-29 Thread conan
Thank you, i have read this but somehow a missed it when the issue arose. -- http://mail.python.org/mailman/listinfo/python-list

Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-28 Thread Paul McGuire
"conan" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This regexp > '' > > works well with 'grep' for matching lines of the kind > > > on a XML .glade file > As Peter Otten has already mentioned, this is the difference between the re "match" and "search" methods. As purely a late

Re: unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-28 Thread Peter Otten
conan wrote: > The thing is i should expected to have to put caret explicitly to tell > the regexp to match at the start of the line, something like: > r'^' > however python regexp is taking care of that for me. This is not a > desired behaviour for what i know about rege

unexpected behaviour for python regexp: caret symbol almost useless?

2006-05-28 Thread conan
f good_regexp.match(line): print 'good:', line.strip() The thing is i should expected to have to put caret explicitly to tell the regexp to match at the start of the line, something like: r'^' however python regexp is taking care of that for me. This is not a desired behaviour for what i know about regexp, but maybe i'm missing something. -- http://mail.python.org/mailman/listinfo/python-list

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread [EMAIL PROTECTED]
Neat! I didn't realize that re.sub could take a function as an argument. Thanks. Lorin -- http://mail.python.org/mailman/listinfo/python-list

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Lonnie Princehouse
> Is there some equivalent feature in Python regexps? cpp_pat = re.compile('(/\*.*?\*/)|(".*?")', re.S) def subfunc(match): if match.group(2): return match.group(2) else: return '' stripped_c_code = cpp_pat.sub(subfunc, c_code) ...I suppose this is what the Perl code might do, but

Re: Stripping C-style comments using a Python regexp

2005-07-27 Thread Jeff Epler
# import re, sys def q(c): """Returns a regular expression that matches a region delimited by c, inside which c may be escaped with a backslash""" return r"%s(\\.|[^%s])*%s" % (c, c, c) single_quoted_string = q('

Stripping C-style comments using a Python regexp

2005-07-27 Thread [EMAIL PROTECTED]
Hi Folks, I'm trying to strip C/C++ style comments (/* ... */ or // ) from source code using Python regexps. If I don't have to worry about comments embedded in strings, it seems pretty straightforward (this is what I'm using now): cpp_pat = re.compile(r""" /\* .*? \*/ |# C comm

Re: Python RegExp

2005-03-22 Thread D H
[EMAIL PROTECTED] wrote: I have a string which I wish to match using RE, however when I run my comparison (using the match method) on my machine it never returns, using the CPU fully. In your case it may be simpler to just split the string into groups. You don't even need regular expressions or a

Re: Python RegExp

2005-03-22 Thread David Chipping
Jeff, Thanks very much for that, I didn't even consider the option of it finishing, considering I'm using a much slower machine it was running for over 2 minutes when I just killed it! I think I get the rest now. Cheers again, -David On Tue, 22 Mar 2005 17:52:22 -0600, Jeff Epler <[EMAIL PROTE

Re: Python RegExp

2005-03-22 Thread Jeff Epler
On my machine the program finishes in 30 seconds. (it's a 1.5GHz machine) If the 'parm' group is removed, or if the buffer is shortened, the time is reduced considerably. There are "pathological cases" for regular expressions which can take quite a long time. In the case of your expression, it's

Re: Python RegExp

2005-03-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: >I have a string which I wish to match using RE, however when I run my > comparison (using the match method) on my machine it never returns, > using the CPU fully. > > The code is (very simply): > > -- > import re > > buffer = r"#1 1 550 111 SYN

Python RegExp

2005-03-22 Thread davidchipping
I have a string which I wish to match using RE, however when I run my comparison (using the match method) on my machine it never returns, using the CPU fully. The code is (very simply): -- import re buffer = r"#1 1 550 111 SYNC_PEER RES syncpeers=(id=54325432;add=10."