Re: RegExp - please help me!

2017-12-27 Thread szykcech
> (?s)struct (.+?)\s*\{\s*(.+?)\s*\}; Thank you Vlastimil Brom for regexp and for explanation! -- https://mail.python.org/mailman/listinfo/python-list

Re: RegExp - please help me!

2017-12-27 Thread Lele Gaifax
szykc...@gmail.com writes: > Please help me with this regexp or tell me that I neeed do this in other way. I think that using regexps to parse those structures is fragile and difficult to get right[0], as there are lots of corner cases (comments, complex types, ...). I'd suggest using a tool des

Re: RegExp - please help me! (Posting On Python-List Prohibited)

2017-12-26 Thread szykcech
W dniu wtorek, 26 grudnia 2017 21:53:14 UTC+1 użytkownik Lawrence D’Oliveiro napisał: > On Wednesday, December 27, 2017 at 2:15:21 AM UTC+13, szyk...@gmail.com wrote: > > struct (.+)\s*{\s*(.+)\s*}; > > You realize that “.” matches anything? Whereas I think you want to match > non-whitespace in

Re: RegExp - please help me!

2017-12-26 Thread Peter Pearson
On Tue, 26 Dec 2017 05:14:55 -0800 (PST), szykc...@gmail.com wrote: [snip] > So: I develop regexp which to my mind should work, but it doesn't and > I don't know why. The broken regexp is like this: > struct (.+)\s*{\s*(.+)\s*}; [snip] You'll probably get better help faster if you can present you

Re: RegExp - please help me!

2017-12-26 Thread Vlastimil Brom
Hi, I can't comment, whether this is the right approach, as I have no experiences with C++, but for the matching regular expression itself, I believe, e.g. the following might work for your sample data (I am not sure, however, what other details or variants should be taken into account): (?s)struc

Re: RegExp help

2016-02-10 Thread MRAB
On 2016-02-11 03:09, Larry Martell wrote: On Wed, Feb 10, 2016 at 10:00 PM, MRAB wrote: On 2016-02-11 02:48, Larry Martell wrote: Given this string: s = """|Type=Foo ... |Side=Left""" print s |Type=Foo |Side=Left I can match with this: m = re.search(r'^\|Type=(.*)$\n^\|Side=(.*)$',

Re: RegExp help

2016-02-10 Thread Larry Martell
On Wed, Feb 10, 2016 at 10:00 PM, MRAB wrote: > On 2016-02-11 02:48, Larry Martell wrote: >> >> Given this string: >> > s = """|Type=Foo >> >> ... |Side=Left""" > > print s >> >> |Type=Foo >> |Side=Left >> >> I can match with this: >> > m = re.search(r'^\|Type=(.*)$\n^\|Side=(.*)$'

Re: RegExp help

2016-02-10 Thread MRAB
On 2016-02-11 02:48, Larry Martell wrote: Given this string: s = """|Type=Foo ... |Side=Left""" print s |Type=Foo |Side=Left I can match with this: m = re.search(r'^\|Type=(.*)$\n^\|Side=(.*)$',s,re.MULTILINE) print m.group(0) |Type=Foo |Side=Left print m.group(1) Foo print m.group(2)

Re: regexp partial matching, or hitEnd

2012-04-05 Thread Terry Reedy
On 4/5/2012 8:19 AM, Mark Lawrence wrote: More likely to go into the new regex module that's on pypi. Talking of which is this going into Python 3.3, I see it's mentioned in PEP398 but can't find any mention in the Python 3.3 What's New docs, or have I simply missed something? I think it has b

Re: regexp partial matching, or hitEnd

2012-04-05 Thread Mark Lawrence
On 05/04/2012 08:29, Константин Куликов wrote: I want something like this in python : http://stackoverflow.com/questions/2526756/can-java-util-regex-pattern-do-partia... First you have to call one of the

Re: Regexp : repeated group identification

2011-12-14 Thread Vlastimil Brom
2011/12/14 candide : ... > > Thanks for the reference and the example. I didn't know of this > reimplementation, hoping it offers the Aho-Corasick algorithm allowing > multiple keys search. > -- > http://mail.python.org/mailman/listinfo/python-list Hi, I am not sure about the underlying algorithm

Re: Regexp : repeated group identification

2011-12-14 Thread candide
Le 14/12/2011 12:34, Vlastimil Brom a écrit : "If a group is contained in a part of the pattern that matched multiple times, the last match is returned." I missed this point, your answer matches my question ;) thanks. If you need to work with the content captured in the repeated group, you

Re: Regexp : repeated group identification

2011-12-14 Thread Vlastimil Brom
2011/12/14 candide : > Consider the following code > > # > import re > > z=re.match('(Spam\d)+', 'Spam4Spam2Spam7Spam8') > print z.group(0) > print z.group(1) > # > > outputting : > > > Spam4Spam2Spam7Spam8 > Spa

Re: regexp compilation error

2011-10-11 Thread Ovidiu Deac
Thanks for the answer. I will give a try to pypy regex. On Fri, Sep 30, 2011 at 4:56 PM, Vlastimil Brom wrote: > 2011/9/30 Ovidiu Deac : >> This is only part of a regex taken from an old perl application which >> we are trying to understand/port to our new Python implementation. >> >> The origina

Re: regexp compilation error

2011-09-30 Thread Vlastimil Brom
2011/9/30 Ovidiu Deac : > This is only part of a regex taken from an old perl application which > we are trying to understand/port to our new Python implementation. > > The original regex was considerably more complex and it didn't compile > in python so I removed all the parts I could in order to

Re: regexp compilation error

2011-09-30 Thread Hans Mulder
On 30/09/11 11:10:48, Ovidiu Deac wrote: I have the following regexp which fails to compile. Can somebody explain why? re.compile(r"""^(?: [^y]* )*""", re.X) [...] sre_constants.error: nothing to repeat Is this a bug or a feature? A feature: the message explains why this pattern is not all

Re: regexp compilation error

2011-09-30 Thread Steven D'Aprano
Ovidiu Deac wrote: re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.6/re.py", line 190, in compile > return _compile(pattern, flags) > File "/usr/lib/python2.6/re.py", line 245, in _compile > raise error,

Re: regexp compilation error

2011-09-30 Thread Ovidiu Deac
This is only part of a regex taken from an old perl application which we are trying to understand/port to our new Python implementation. The original regex was considerably more complex and it didn't compile in python so I removed all the parts I could in order to isolate the problem such that I c

Re: regexp compilation error

2011-09-30 Thread Chris Angelico
On Fri, Sep 30, 2011 at 7:26 PM, Ovidiu Deac wrote: > $ python --version > Python 2.6.6 Ah, I think I was misinterpreting the traceback. You do actually have a useful message there; it's the same error that my Py3.2 produced: sre_constants.error: nothing to repeat I'm not sure what your regex i

Re: regexp compilation error

2011-09-30 Thread Ovidiu Deac
$ python --version Python 2.6.6 On Fri, Sep 30, 2011 at 12:18 PM, Chris Angelico wrote: > On Fri, Sep 30, 2011 at 7:10 PM, Ovidiu Deac wrote: >> I have the following regexp which fails to compile. Can somebody explain why? >> > re.compile(r"""^(?: [^y]* )*""", re.X) >> Traceback (most recen

Re: regexp compilation error

2011-09-30 Thread Chris Angelico
On Fri, Sep 30, 2011 at 7:10 PM, Ovidiu Deac wrote: > I have the following regexp which fails to compile. Can somebody explain why? > re.compile(r"""^(?: [^y]* )*""", re.X) > Traceback (most recent call last): >  File "", line 1, in >  File "/usr/lib/python2.6/re.py", line 190, in compile >

Re: regexp matching end of line or comma

2010-11-25 Thread Saul Spatz
On Nov 25, 8:40 am, Jean-Michel Pichavant wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of > line '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) > m2 = re.match('(?P\S+)$', ex2) > m3 = re.match('(?P\S+)[,$]', ex

Re: regexp matching end of line or comma

2010-11-25 Thread MRAB
On 25/11/2010 16:26, Jean-Michel Pichavant wrote: MRAB wrote: On 25/11/2010 14:40, Jean-Michel Pichavant wrote: Hy guys, I'm struggling matching patterns ending with a comma ',' or an end of line '$'. import re ex1 = 'sumthin,' ex2 = 'sumthin' m1 = re.match('(?P\S+),', ex1) m2 = re.match('(?

Re: regexp matching end of line or comma

2010-11-25 Thread Jean-Michel Pichavant
MRAB wrote: On 25/11/2010 14:40, Jean-Michel Pichavant wrote: Hy guys, I'm struggling matching patterns ending with a comma ',' or an end of line '$'. import re ex1 = 'sumthin,' ex2 = 'sumthin' m1 = re.match('(?P\S+),', ex1) m2 = re.match('(?P\S+)$', ex2) m3 = re.match('(?P\S+)[,$]', ex1) m4

Re: regexp matching end of line or comma

2010-11-25 Thread MRAB
On 25/11/2010 14:40, Jean-Michel Pichavant wrote: Hy guys, I'm struggling matching patterns ending with a comma ',' or an end of line '$'. import re ex1 = 'sumthin,' ex2 = 'sumthin' m1 = re.match('(?P\S+),', ex1) m2 = re.match('(?P\S+)$', ex2) m3 = re.match('(?P\S+)[,$]', ex1) m4 = re.match('(

Re: regexp matching end of line or comma

2010-11-25 Thread Sol Toure
Try this: '(?P\S+)(,|$)' On Thu, Nov 25, 2010 at 9:40 AM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > Hy guys, > > I'm struggling matching patterns ending with a comma ',' or an end of line > '$'. > > import re > > ex1 = 'sumthin,' > ex2 = 'sumthin' > m1 = re.match('(?P\S+),', ex1) >

Re: Regexp problem when parsing a string

2010-03-21 Thread MRAB
Alessandro Marino wrote: I'm a beginner and I was trying to write a program to parse recursively all file names in a directory specified as parameter. The problem is that I get a "None" printed to stdout when a file is positively matched. While when the file name doesn't match the regexp the o

Re: Regexp problem when parsing a string

2010-03-21 Thread Steven D'Aprano
On Sun, 21 Mar 2010 19:12:18 +0100, Alessandro Marino wrote: > Could anyone help me to figure out why "None" appears in the putput? I get: "Attachment not shown: MIME type application/octet-stream; filename a.py" Posting attachments to Usenet is tricky. Many newsgroups filter out anything they

Re: Regexp and multiple groups (with repeats)

2009-11-20 Thread Mark Tolonen
"mk" wrote in message news:he60ha$iv...@ger.gmane.org... Hello, >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') >>> r.search(r'c:/tmp/spam/eggs').groups() ('/eggs',) Obviously, I would like to capture all groups: ('/tmp', '/spam', '/eggs') But it seems that re captures only the last group. Is

Re: Regexp and multiple groups (with repeats)

2009-11-20 Thread Neil Cerutti
On 2009-11-20, mk wrote: > Hello, > > >>> r=re.compile(r'(?:[a-zA-Z]:)([\\/]\w+)+') > > >>> r.search(r'c:/tmp/spam/eggs').groups() > ('/eggs',) > > Obviously, I would like to capture all groups: > ('/tmp', '/spam', '/eggs') You'll have to do something else, for example: >>> s = re.compile(r'(?:[

Re: regexp help

2009-11-04 Thread Dave Angel
Simon Brunning wrote: 2009/11/4 Nadav Chernin : Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. How about: os.path.splitext(x)[1] in (".exe", ".dll", ".ocx", ".py"): DaveA -- http://mail.python.org/mailman/list

Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin : > No, I need all files except exe|dll|ocx|py not re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) Now that wasn't so hard, was it? ;-) -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list

RE: regexp help

2009-11-04 Thread Nadav Chernin
No, I need all files except exe|dll|ocx|py -Original Message- From: simon.brunn...@gmail.com [mailto:simon.brunn...@gmail.com] On Behalf Of Simon Brunning Sent: ד 04 נובמבר 2009 19:13 To: Nadav Chernin Cc: Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > Thanks, but

Re: regexp help

2009-11-04 Thread Carsten Haese
Nadav Chernin wrote: > Thanks, but my question is how to write the regex. See http://www.amk.ca/python/howto/regex/ . -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list

Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin : > Thanks, but my question is how to write the regex. re.match(r'.*\.(exe|dll|ocx|py)$', the_file_name) works for me. -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list

RE: regexp help

2009-11-04 Thread Nadav Chernin
Thanks, but my question is how to write the regex. -Original Message- From: simon.brunn...@gmail.com [mailto:simon.brunn...@gmail.com] On Behalf Of Simon Brunning Sent: ד 04 נובמבר 2009 18:44 To: Nadav Chernin; Python List Subject: Re: regexp help 2009/11/4 Nadav Chernin : > I’m try

Re: regexp help

2009-11-04 Thread Simon Brunning
2009/11/4 Nadav Chernin : > I’m trying to write regexp that find all files that are not with next > extensions:  exe|dll|ocx|py,  but can’t find any command that make it. http://code.activestate.com/recipes/499305/ should be a good start. Use the re module and your regex instead of fnmatch.filter(

Re: regexp help

2009-08-27 Thread Paul McGuire
On Aug 27, 1:15 pm, Bakes wrote: > If I were using the code: > > (?P[0-9]+) > > to get an integer between 0 and 9, how would I allow it to register > negative integers as well? With that + sign in there, you will actually get an integer from 0 to 9... -- Paul -- http://mail.pyth

Re: regexp help

2009-08-27 Thread Mart.
On Aug 27, 7:15 pm, Bakes wrote: > If I were using the code: > > (?P[0-9]+) > > to get an integer between 0 and 9, how would I allow it to register > negative integers as well? -? -- http://mail.python.org/mailman/listinfo/python-list

Re: regexp help

2009-08-27 Thread Peter Pearson
On Thu, 27 Aug 2009 11:15:59 -0700 (PDT), Bakes wrote: > If I were using the code: > > (?P[0-9]+) > > to get an integer between 0 and 9, how would I allow it to register > negative integers as well? (?P-?[0-9]+) -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.o

Re: regexp help

2009-08-27 Thread Iuri
You can use r"[+-]?\d+" to get positive and negative integers. It returns true to these strings: "+123", "-123", "123" On Thu, Aug 27, 2009 at 3:15 PM, Bakes wrote: > If I were using the code: > > (?P[0-9]+) > > to get an integer between 0 and 9, how would I allow it to register > negative in

Re: Regexp problem

2009-07-31 Thread Ethan Furman
MRAB wrote: Ethan Furman wrote: Marcus Wanner wrote: Wow, I really need to learn more about regexp... Any tutorials you guys can recommend? Marcus Mastering Regular Expressions Powerful Techniques for Perl and Other Tools By Jeffrey E. F. Friedl Great book! +1 I have the first edition,

Re: Regexp problem

2009-07-30 Thread MRAB
Ethan Furman wrote: Marcus Wanner wrote: On 7/30/2009 9:32 AM, Beldar wrote: On 30 jul, 15:07, MRAB wrote: Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to

Re: Regexp problem

2009-07-30 Thread Ethan Furman
Marcus Wanner wrote: On 7/30/2009 9:32 AM, Beldar wrote: On 30 jul, 15:07, MRAB wrote: Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part

Re: Regexp problem

2009-07-30 Thread Peter Brett
Marcus Wanner writes: > On 7/30/2009 9:32 AM, Beldar wrote: >> On 30 jul, 15:07, MRAB wrote: >>> Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp

Re: Regexp problem

2009-07-30 Thread Marcus Wanner
On 7/30/2009 9:32 AM, Beldar wrote: On 30 jul, 15:07, MRAB wrote: Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'somethin

Re: Regexp problem

2009-07-30 Thread Beldar
On 30 jul, 15:07, MRAB wrote: > Beldar wrote: > > Hi there! > > > I have a problem and i'm not very good at regular expressions. > > I have a text like "lalala lalala tiruri beldar-is-listening tiruri > > lalala" I need a regexp to get the 'beldar' part, the format is > > 'something-is-listening',

Re: Regexp problem

2009-07-30 Thread MRAB
Beldar wrote: Hi there! I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code

Re: Regexp problem

2009-07-30 Thread Tim Chase
I have a problem and i'm not very good at regular expressions. I have a text like "lalala lalala tiruri beldar-is-listening tiruri lalala" I need a regexp to get the 'beldar' part, the format is 'something-is-listening', i need to get the something part, use it in my code, and then replace the who

Re: regexp strangeness

2009-04-10 Thread Steven D'Aprano
On Thu, 09 Apr 2009 20:48:11 +0100, Dale Amon wrote: > This finds nothing: ... > DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!);\\\]%_>?]") > This works correctly: ... > DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!)\\;\]%_>?]") > They differ only in the positioning of th

Re: regexp strangeness

2009-04-09 Thread MRAB
Peter Otten wrote: Dale Amon wrote: This finds nothing: import re import string card = "abcdef" DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!);\\\]%_>?]") The regular expression you're actually providing is: >>> print "[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!);\\\]%_>?]" [^&0-9A-Z/

Re: regexp strangeness

2009-04-09 Thread Peter Otten
Dale Amon wrote: > This finds nothing: > > import re > import string > card = "abcdef" > DEC029 = re.compile("[^&0-9A-Z/ $*,.\-:#@'=\"[<(+\^!);\\\]%_>?]") > errs = DEC029.findall(card.strip("\n\r")) > print errs > > This works correctly: > > import re > import string > card

Re: Regexp

2009-01-19 Thread Diez B. Roggisch
gervaz wrote: > On Jan 19, 4:01 pm, Ant wrote: >> A 0-width positive lookahead is probably what you want here: >> >> >>> s = """ >> >> ... hdhd http://mysite.com/blah.html";>Test String OK> a> >> ... >> ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >> >>> m = re.search(p, s) >> >>>

Re: Regexp

2009-01-19 Thread gervaz
On Jan 19, 4:01 pm, Ant wrote: > A 0-width positive lookahead is probably what you want here: > > >>> s = """ > > ... hdhd http://mysite.com/blah.html";>Test String OK a> > ... > ... """>>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' > >>> m = re.search(p, s) > >>> m.group(1) > > 'http://mysi

Re: Regexp

2009-01-19 Thread Ant
A 0-width positive lookahead is probably what you want here: >>> s = """ ... hdhd http://mysite.com/blah.html";>Test String OK ... ... """ >>> p = r'href="(http://mysite.com/[^"]+)">(.*)(?=)' >>> m = re.search(p, s) >>> m.group(1) 'http://mysite.com/blah.html' >>> m.group(2) 'Test String OK' The

Re: Regexp

2009-01-19 Thread Peter Otten
gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not s

Re: Regexp

2009-01-19 Thread Diez B. Roggisch
gervaz wrote: > Hi all, I need to find all the address in a html source page, I'm > using: > 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)( b>)?' > but the [^]+ pattern retrieve all the strings not containing < > or / or a etc, although I just not want the word "". How can I > specify: 'do not s

Re: Regexp

2009-01-19 Thread MRAB
gervaz wrote: Hi all, I need to find all the address in a html source page, I'm using: 'href="(?Phttp://mysite.com/[^"]+)">()?(?P[^]+)()?' but the [^]+ pattern retrieve all the strings not containing < or / or a etc, although I just not want the word "". How can I specify: 'do not search the stri

Re: Regexp parser and generator

2008-11-05 Thread George Sakkis
On Nov 4, 3:30 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > Is there any package that parses regular expressions and returns an > > AST ? Something like: > > parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') > > Regex('i ', Or('love', 'hate'), ' h', Or('is', 'er'),

Re: Regexp parser and generator

2008-11-05 Thread George Sakkis
On Nov 4, 9:56 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Nov 4, 1:34 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > Is there any package that parses regular expressions and returns an > > AST ? Something like: > > > >>> parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') > > > Regex

Re: Regexp parser and generator

2008-11-04 Thread Paul McGuire
On Nov 4, 1:34 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > Is there any package that parses regular expressions and returns an > AST ? Something like: > > >>> parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') > > Regex('i ', Or('love', 'hate'), ' h', Or('is', 'er'), ' ', Or('cat', > 'dog'), O

Re: Regexp parser and generator

2008-11-04 Thread Peter Otten
George Sakkis wrote: > Is there any package that parses regular expressions and returns an > AST ? Something like: > parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') > Regex('i ', Or('love', 'hate'), ' h', Or('is', 'er'), ' ', Or('cat', > 'dog'), Optional('s'), ZeroOrMore(r'\s'), OneOrMo

Re: Regexp parser and generator

2008-11-04 Thread skip
George> Is there any package that parses regular expressions and returns George> an AST ? Maybe not directly, but this might provide a starting point for building such a beast: >>> import re >>> re.compile("[ab]", 128) in literal 97 literal 98 <_sre.SRE_Patter

Re: regexp in Python (from Perl)

2008-10-24 Thread Pat
Bruno Desthuilliers wrote: MRAB a écrit : On Oct 19, 5:47 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: Pat a écrit : (snip) ip = ip[ :-1 ] ip =+ '9' or: ip = ip[:-1]+"9" (snip) >>> re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.1") '192.168.1.9' re.sub(r'^(((\d+)\.){3})\d+$

Re: regexp in Python (from Perl)

2008-10-20 Thread Bruno Desthuilliers
Pat a écrit : Bruno Desthuilliers wrote: Pat a écrit : I have a regexp in Perl that converts the last digit of an ip address to '9'. This is a very particular case so I don't want to go off on a tangent of IP octets. ( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ; While I can do this in P

Re: regexp in Python (from Perl)

2008-10-20 Thread Pat
Bruno Desthuilliers wrote: Pat a écrit : I have a regexp in Perl that converts the last digit of an ip address to '9'. This is a very particular case so I don't want to go off on a tangent of IP octets. ( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ; While I can do this in Python which acc

Re: regexp in Python (from Perl)

2008-10-20 Thread Bruno Desthuilliers
MRAB a écrit : On Oct 19, 5:47 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: Pat a écrit : (snip) ip = ip[ :-1 ] ip =+ '9' or: ip = ip[:-1]+"9" (snip) >>> re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.1") '192.168.1.9' re.sub(r'^(((\d+)\.){3})\d+$', "\g<1>9", "192.168.1.100"

Re: regexp in Python (from Perl)

2008-10-19 Thread bearophileHUGS
MRAB: > The regular expression changes the last sequence of digits to > "9" ("192.168.1.100" => "192.168.1.9") but the other code replaces the > last digit ("192.168.1.100" => "192.168.1.109"). Uhmm, this is a possible alternative: >>> s = " 192.168.1.100 " >>> ".".join(s.strip().split(".")[:3])

Re: regexp in Python (from Perl)

2008-10-19 Thread MRAB
On Oct 19, 5:47 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Pat a écrit : > > > I have a regexp in Perl that converts the last digit of an ip address to > >  '9'.  This is a very particular case so I don't want to go off on a > > tangent of IP octets. > > >  ( my $s = $str ) =~ s/((\d+\.){

Re: regexp in Python (from Perl)

2008-10-19 Thread Bruno Desthuilliers
Pat a écrit : I have a regexp in Perl that converts the last digit of an ip address to '9'. This is a very particular case so I don't want to go off on a tangent of IP octets. ( my $s = $str ) =~ s/((\d+\.){3})\d+/${1}9/ ; While I can do this in Python which accomplishes the same thing: i

Re: RegExp: "wontmatch"-function

2008-10-13 Thread william tanksley
On Oct 13, 9:40 am, [EMAIL PROTECTED] wrote: > I'm looking for a function which, given a regexp re and  and a string > str, returns whether re won't match any string starting with str. (so > it would always return False if str is "" or if str itself matches re > -- but that are only the easy cases)

Re: RegExp: "wontmatch"-function

2008-10-13 Thread Kirk Strauser
At 2008-10-13T16:40:07Z, [EMAIL PROTECTED] writes: def nomatch(value): return not(value == '' or pattern.match(value)) -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list

Re: regexp: match only if previous matched?

2008-06-23 Thread Carl Banks
On Jun 23, 6:02 pm, cirfu <[EMAIL PROTECTED]> wrote: > I need to extract prices froma html-document. > > [0-9]*\$ matches 112$ 45$ etc but also just a $. why that shouldnt > really matter and it is unlikely anyway to appear a $sign with no > price attahced to it I still want to prevent it. > > How

Re: regexp: match only if previous matched?

2008-06-23 Thread Vlastimil Brom
2008/6/24, cirfu <[EMAIL PROTECTED]>: > > I need to extract prices froma html-document. > > [0-9]*\$ matches 112$ 45$ etc but also just a $. why that shouldnt > really matter and it is unlikely anyway to appear a $sign with no > price attahced to it I still want to prevent it. > > How do I avoid ma

Re: regexp help

2008-05-09 Thread Paul McGuire
On May 9, 6:52 pm, John Machin <[EMAIL PROTECTED]> wrote: > Paul McGuire wrote: > > from re import * > > Perhaps you intended "import re". Indeed I did. > > > > Both print "prince". > > No they don't. The result is "NameError: name 're' is not defined". Dang, now how did that work in my script?

Re: regexp help

2008-05-09 Thread John Machin
globalrev wrote: The inner pair of () are not necessary. yes they are? You are correct. I was having a flashback to a dimly remembered previous incarnation during which I used regexp software in which something like & or \0 denoted the whole match (like MatchObject.group(0)) :-) -- http://

Re: regexp help

2008-05-09 Thread globalrev
> The inner pair of () are not necessary. yes they are? ty anyway, got it now. -- http://mail.python.org/mailman/listinfo/python-list

Re: regexp help

2008-05-09 Thread John Machin
globalrev wrote: ty. that was the decrypt function. i am slo writing an encrypt function. def encrypt(phrase): pattern = re.compile(r"([bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ])") The inner pair of () are not necessary. return pattern.sub(r"1\o\1", phrase) doesnt work though, h b

Re: regexp help

2008-05-09 Thread globalrev
ty. that was the decrypt function. i am slo writing an encrypt function. def encrypt(phrase): pattern = re.compile(r"([bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ])") return pattern.sub(r"1\o\1", phrase) doesnt work though, h becomes 1\\oh. def encrypt(phrase): pattern = re.compile(r

Re: regexp help

2008-05-09 Thread John Machin
Paul McGuire wrote: from re import * Perhaps you intended "import re". vowels = "aAeEiIoOuU" cons = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ" encodeRe = re.compile(r"([%s])[%s]\1" % (cons,vowels)) print encodeRe.sub(r"\1",s) This is actually a little more complex than you asked - it will

Re: regexp help

2008-05-09 Thread Matimus
On May 9, 3:19 pm, globalrev <[EMAIL PROTECTED]> wrote: > i want to a little stringmanipulationa nd im looking into regexps. i > couldnt find out how to do: > s = 'poprorinoncoce' > re.sub('$o$', '$', s) > should result in 'prince' > > $ is obv the wrng character to use bu what i mean the pattern i

Re: regexp help

2008-05-09 Thread Paul McGuire
On May 9, 5:19 pm, globalrev <[EMAIL PROTECTED]> wrote: > i want to a little stringmanipulationa nd im looking into regexps. i > couldnt find out how to do: > s = 'poprorinoncoce' > re.sub('$o$', '$', s) > should result in 'prince' > > $ is obv the wrng character to use bu what i mean the pattern i

Re: RegExp Help

2007-12-14 Thread Sean DiZazzo
On Dec 14, 3:06 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 14 Dec 2007 06:06:21 -0300, Sean DiZazzo <[EMAIL PROTECTED]> > escribió: > > > > > On Dec 14, 12:04 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >> On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: > >

Re: RegExp Help

2007-12-14 Thread Gabriel Genellina
En Fri, 14 Dec 2007 06:06:21 -0300, Sean DiZazzo <[EMAIL PROTECTED]> escribió: > On Dec 14, 12:04 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: >> > I'm wrapping up a command line util that returns xml in Python. The >> > util

Re: RegExp Help

2007-12-14 Thread Sean DiZazzo
On Dec 14, 12:04 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: > > I'm wrapping up a command line util that returns xml in Python. The > > util is flaky, and gives me back poorly formed xml with different > > problems in different

Re: RegExp Help

2007-12-14 Thread Marc 'BlackJack' Rintsch
On Thu, 13 Dec 2007 17:49:20 -0800, Sean DiZazzo wrote: > I'm wrapping up a command line util that returns xml in Python. The > util is flaky, and gives me back poorly formed xml with different > problems in different cases. Anyway I'm making progress. I'm not > very good at regular expressions

Re: RegExp Help

2007-12-13 Thread Sean DiZazzo
On Dec 13, 5:49 pm, Sean DiZazzo <[EMAIL PROTECTED]> wrote: > Hi group, > > I'm wrapping up a command line util that returns xml in Python. The > util is flaky, and gives me back poorly formed xml with different > problems in different cases. Anyway I'm making progress. I'm not > very good at re

Re: regexp search on infinite string?

2007-09-15 Thread Paddy
On Sep 15, 2:07 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Sep 15, 10:56 pm, Paddy <[EMAIL PROTECTED]> wrote: > > > > > On Sep 14, 9:49 pm, Paddy <[EMAIL PROTECTED]> wrote: > > > > Lets say i have a generator running that generates successive > > > characters of a 'string'>From what I know, if

Re: regexp search on infinite string?

2007-09-15 Thread John Machin
On Sep 15, 10:56 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Sep 14, 9:49 pm, Paddy <[EMAIL PROTECTED]> wrote: > > > Lets say i have a generator running that generates successive > > characters of a 'string'>From what I know, if I want to do a regexp search > > for a pattern of > > > characters then

Re: regexp search on infinite string?

2007-09-15 Thread Paddy
On Sep 14, 9:49 pm, Paddy <[EMAIL PROTECTED]> wrote: > Lets say i have a generator running that generates successive > characters of a 'string'>From what I know, if I want to do a regexp search > for a pattern of > > characters then I would have to 'freeze' the generator and pass the > characters

Re: regexp search on infinite string?

2007-09-15 Thread John Machin
On Sep 15, 4:36 pm, Paddy <[EMAIL PROTECTED]> wrote: > On Sep 15, 2:57 am, James Stroud <[EMAIL PROTECTED]> wrote: > > > > > Paddy wrote: > > > Lets say i have a generator running that generates successive > > > characters of a 'string' > > >>From what I know, if I want to do a regexp search for a

Re: regexp search on infinite string?

2007-09-14 Thread Paddy
On Sep 15, 2:57 am, James Stroud <[EMAIL PROTECTED]> wrote: > Paddy wrote: > > Lets say i have a generator running that generates successive > > characters of a 'string' > >>From what I know, if I want to do a regexp search for a pattern of > > characters then I would have to 'freeze' the generator

Re: regexp search on infinite string?

2007-09-14 Thread James Stroud
Paddy wrote: > Lets say i have a generator running that generates successive > characters of a 'string' >>From what I know, if I want to do a regexp search for a pattern of > characters then I would have to 'freeze' the generator and pass the > characters so far to re.search. > It is expensive to

Re: regexp problem in Python

2007-08-07 Thread Ant
On Aug 3, 10:41 pm, Ehsan <[EMAIL PROTECTED]> wrote: ... > what can I do? what's wrong whit this pattern? thanx for your comments Nothing. There's something wrong with the code you are using the regex with. Post it and we may be able to help. Like Lawrence has said, it's likely to be that you are

Re: regexp problem in Python

2007-08-06 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Ehsan wrote: > I use this pattern : > "http.*?\.(wmv|3gp).*"" > > but it returns only 'wmv' and '3gp' instead of "http://www.2shared.com/ > download/1716611/e2000f22/Jadeed_Mlak14.wmv? > tsid=20070803-164051-9d637d11" What's the actual Python code that uses this r

Re: regexp problem in Python

2007-08-04 Thread Sönmez Kartal
On 4 A ustos, 17:10, Ehsan <[EMAIL PROTECTED]> wrote: > On Aug 4, 1:22 pm, Sönmez Kartal <[EMAIL PROTECTED]> wrote: > > > > > > > > > On 4 A ustos, 00:41, Ehsan <[EMAIL PROTECTED]> wrote: > > > > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > > > Jadeed_Mlak14.wmv?tsid=20070803

Re: regexp problem in Python

2007-08-04 Thread Fabio Z Tessitore
Il Fri, 03 Aug 2007 14:41:52 -0700, Ehsan ha scritto: maybe you can use this to solve your prob: myurl = "http://www.2shared.com/download/1716611/e2000f22/ Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" if myurl.startswith('http') and ('wmv' in myurl or '3pg' in myurl): # myurl is the

Re: regexp problem in Python

2007-08-04 Thread Ehsan
On Aug 4, 1:22 pm, Sönmez Kartal <[EMAIL PROTECTED]> wrote: > On 4 A ustos, 00:41, Ehsan <[EMAIL PROTECTED]> wrote: > > > > > > > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > > Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" or 3gp instead of > > wmv in the text file like t

Re: regexp problem in Python

2007-08-04 Thread Sönmez Kartal
On 4 A ustos, 00:41, Ehsan <[EMAIL PROTECTED]> wrote: > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > Jadeed_Mlak14.wmv?tsid=20070803-164051-9d637d11" or 3gp instead of > wmv in the text file like this : > > ""some code"" > function reportAbuse() { > var windowname="abus

Re: regexp problem in Python

2007-08-03 Thread Ehsan
On Aug 4, 1:36 am, Dave Hansen <[EMAIL PROTECTED]> wrote: > On Aug 3, 4:41 pm, Ehsan <[EMAIL PROTECTED]> wrote: > > > I want to find "http://www.2shared.com/download/1716611/e2000f22/ > [...] > > I use this pattern : > > "http.*?\.(wmv|3gp).*"" > > > but it returns only 'wmv' and '3gp' instead of "

  1   2   >