Re: Using ascii numbers in regular expression

2009-04-30 Thread MRAB
Lie Ryan wrote: MRAB wrote: You're almost there: re.subn('\x61','b','') or better yet: re.subn(r'\x61','b','') Wouldn't that becomes a literal \x61 instead of a as it is inside raw string? Yes. The re module will understand the \x sequence within a regular expression

regular expression, unicode

2009-04-29 Thread Simon Strobl
Hello, why can't I use this pattern good = re.compile(^[A-ZÄÖÜ].*) in python3. According to the documentation, patterns may be unicode strings. I get this error message: Traceback (most recent call last): File ./get.py, line 8, in module for line in sys.stdin: File

Re: regular expression, unicode

2009-04-29 Thread Rhodri James
this is anything to do with the regular expression? It looks more like it's complaining about what you've typed in at the console. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression, unicode

2009-04-29 Thread MRAB
Simon Strobl wrote: Hello, why can't I use this pattern good = re.compile(^[A-ZÄÖÜ].*) in python3. According to the documentation, patterns may be unicode strings. I get this error message: Traceback (most recent call last): File ./get.py, line 8, in module for line in sys.stdin:

regular expression, unicode

2009-04-29 Thread Simon Strobl
Hello, why can't I use this statement in python3: good = re.compile(^[A-ZÄÖÜ].*) According to the documentation, patterns can be unicode strings. I get this error message: Traceback (most recent call last): File ./get.py, line 8, in module for line in sys.stdin: File

[issue5878] Regular Expression instances

2009-04-29 Thread Ezio Melotti
Ezio Melotti ezio.melo...@gmail.com added the comment: Looks like a documentation bug, afaik it has always been _sre.SRE_Pattern object at 0x00A0BB78 (just checked on Python =2.4). Maybe it used to be re.RegexObject instance at 80b4150 in older versions. -- nosy: +ezio.melotti versions:

[issue5878] Regular Expression instances

2009-04-29 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: The output is probably from the stone-aged original re module. Fixed in r72132. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5878

Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Hi, How can I use the ascii number of a character in a regular expression (module re) instead of the character itself? Thanks very much -- http://mail.python.org/mailman/listinfo/python-list

Re: Using ascii numbers in regular expression

2009-04-28 Thread jorma kala
Thanks very much for your reply. What I mean is that I would like to use the ascii number in a regular expression pattern. For instance, if I want to substitute the occurrences of character 'a' for the character 'b' in a string, instead of doing this: re.subn('a','b','') I'd like to specify

Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:58 AM, jorma kala jjk...@gmail.com wrote: Thanks very much for your reply. What I mean is that I would like to use the ascii number in a regular expression pattern. For instance, if I want to substitute the occurrences of character 'a' for the character 'b

Re: Using ascii numbers in regular expression

2009-04-28 Thread Chris Rebert
On Tue, Apr 28, 2009 at 4:05 AM, jorma kala jjk...@gmail.com wrote: Hi, How can I use the ascii number of a character in a regular expression (module re) instead of the character itself? Thanks very much I refer you to the chr() and ord() built-in functions, which can certainly be used

Re: Using ascii numbers in regular expression

2009-04-28 Thread MRAB
jorma kala wrote: Thanks very much for your reply. What I mean is that I would like to use the ascii number in a regular expression pattern. For instance, if I want to substitute the occurrences of character 'a' for the character 'b' in a string, instead of doing this: re.subn('a','b','

Re: Regular expression to capture model numbers

2009-04-24 Thread Piet van Oostrum
John Machin sjmac...@lexicon.net (JM) wrote: JM On Apr 24, 1:29 am, Piet van Oostrum p...@cs.uu.nl wrote: obj = re.compile(r'(?:[a-z]+[-0-9]|[0-9]+[-a-z]|-+[0-9a-z])[-0-9a-z]*', re.I) JM Understandable and maintainable, I don't think. Suppose that instead JM the first character is limited

Re: Regular expression to capture model numbers

2009-04-23 Thread Piet van Oostrum
John Machin sjmac...@lexicon.net (JM) wrote: JM On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: Requirements:   The text must contain a combination of numbers, alphabets and hyphen with at least two of the three elements present. JM Unfortunately(?), regular expressions can't express

Re: Regular expression to capture model numbers

2009-04-23 Thread John Machin
On Apr 24, 1:29 am, Piet van Oostrum p...@cs.uu.nl wrote: John Machin sjmac...@lexicon.net (JM) wrote: JM On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: Requirements:   The text must contain a combination of numbers, alphabets and hyphen with at least two of the three elements

Regular expression to capture model numbers

2009-04-22 Thread krishnapostings
My quick attempt is below: obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') re.findall(obj, 'TestThis;1234;Test123AB-x') ['TestThis', '1234', 'Test123AB-x'] This is not working. Requirements: The text must contain a combination of numbers, alphabets and hyphen with at least two of the three

Re: Regular expression to capture model numbers

2009-04-22 Thread John Machin
On Apr 23, 8:01 am, krishnaposti...@gmail.com wrote: My quick attempt is below: obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') 1. Provided the remainder of the pattern is greedy and it will be used only for findall, the \b seems pointless. 2. What is the | for? Inside a character class, | has no

Re: Regular expression to capture model numbers

2009-04-22 Thread Aahz
In article 1bbafe6d-e3bc-4d90-8a0a-0ca82808b...@d14g2000yql.googlegroups.com, krishnaposti...@gmail.com wrote: My quick attempt is below: obj = re.compile(r'\b[0-9|a-zA-Z]+[\w-]+') re.findall(obj, 'TestThis;1234;Test123AB-x') ['TestThis', '1234', 'Test123AB-x'] This is not working. What isn't

Re: Pathological regular expression

2009-04-17 Thread franck
regular expression, but rather a problem of the RE engine that is not optimized to use the faster approach when possible. This is well known problem very well explained on: http://swtch.com/~rsc/regexp/regexp1.html Cheers, Franck -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression Help

2009-04-13 Thread Graham Breed
Jean-Claude Neveu wrote: Hello, I was wondering if someone could tell me where I'm going wrong with my regular expression. I'm trying to write a regexp that identifies whether a string contains a correctly-formatted currency amount. I want to support dollars, UK pounds and Euros

Re: Pathological regular expression

2009-04-11 Thread Steven D'Aprano
On Thu, 09 Apr 2009 02:56:00 -0700, David Liang wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r'^(([^\\]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-11 Thread MRAB
Steven D'Aprano wrote: On Thu, 09 Apr 2009 02:56:00 -0700, David Liang wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r'^(([^\\]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-11 Thread John Machin
On Apr 12, 1:07 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 09 Apr 2009 02:56:00 -0700, David Liang wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-11 Thread Dotan Cohen
IMHO it's not a bug -- s/hang/takes a long time to compute/ ‎That is quite what a hang is, and why the timeout was invented. The real bug is that there is no timeout mechanism. Just look at it: 2 + operators and 3 * operators ... It's one of those come back after lunch REs. Some users

Re: Pathological regular expression

2009-04-11 Thread MRAB
Dotan Cohen wrote: IMHO it's not a bug -- s/hang/takes a long time to compute/ ‎That is quite what a hang is, and why the timeout was invented. The real bug is that there is no timeout mechanism. I wouldn't call it a hang because it is actually doing work. If it was 'stuck' on a certain

Re: Pathological regular expression

2009-04-11 Thread Aaron Brady
On Apr 11, 10:07 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Thu, 09 Apr 2009 02:56:00 -0700, David Liang wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind, this is a bug in the RE engine. Is there any reason to not treat it as a bug? IMHO it's not a bug -- s/hang/takes a long time to compute/ Just look at it: 2 + operators and 3 * operators ... It's one of those come back

Re: Pathological regular expression

2009-04-11 Thread Dotan Cohen
Well, it's been running now for about two and a half hours, that's a rather long lunch. I'd also like a pony! -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list

Re: Pathological regular expression

2009-04-11 Thread Aaron Brady
On Apr 11, 12:40 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind, this is a bug in the RE engine. Is there any reason to not treat it as a bug? IMHO it's not a bug -- s/hang/takes a long time to compute/

Re: Pathological regular expression

2009-04-11 Thread MRAB
Steven D'Aprano wrote: On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind, this is a bug in the RE engine. Is there any reason to not treat it as a bug? IMHO it's not a bug -- s/hang/takes a long time to compute/ Just look at it: 2 + operators and 3 * operators ... It's one of

Re: Pathological regular expression

2009-04-11 Thread John Machin
On Apr 12, 3:40 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind, this is a bug in the RE engine. Is there any reason to not treat it as a bug? IMHO it's not a bug -- s/hang/takes a long time to compute/

Re: Pathological regular expression

2009-04-11 Thread John Machin
On Apr 12, 9:46 am, John Machin sjmac...@lexicon.net wrote:             result = _re_comments_nc.sub(r\1, line) s/_nc// ... that's an artifact of timing it with Non-Capture groups (?:blahblah) on the two internal groups that don't need to be capturing (results identical, and no perceptible

Re: Pathological regular expression

2009-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2009 16:46:20 -0700, John Machin wrote: On Apr 12, 3:40 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind, this is a bug in the RE engine. Is there any reason to not treat it as a bug? IMHO

Re: Pathological regular expression

2009-04-11 Thread Aaron Brady
On Apr 11, 7:31 pm, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: _ My original test has now been running for close to ten hours now, and still can't be interrupted with ctrl-C. However that's in Python 2.5, having tried it in Python 2.6.2 they can be interrupted, so I'm

Re: Pathological regular expression

2009-04-11 Thread John Machin
On Apr 12, 10:31 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sat, 11 Apr 2009 16:46:20 -0700, John Machin wrote: On Apr 12, 3:40 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Sat, 11 Apr 2009 08:40:03 -0700, John Machin wrote: To my mind,

Regular Expression Help

2009-04-11 Thread Jean-Claude Neveu
Hello, I was wondering if someone could tell me where I'm going wrong with my regular expression. I'm trying to write a regexp that identifies whether a string contains a correctly-formatted currency amount. I want to support dollars, UK pounds and Euros, but the example below deliberately

Re: Regular Expression Help

2009-04-11 Thread rurpy
On Apr 11, 9:42 pm, Jean-Claude Neveu jcn-france1...@pobox.com wrote: My regexp that I'm matching against is: ^\$\£?\d{0,10}(\.\d{2})?$ Here's how I think it should work (but clearly I'm wrong, because it does not actually work): ^\$\£? Require zero or one instance of $ or £ at the

Re: Regular Expression Help

2009-04-11 Thread John Machin
On Apr 12, 2:19 pm, ru...@yahoo.com wrote: On Apr 11, 9:42 pm, Jean-Claude Neveu jcn-france1...@pobox.com wrote: My regexp that I'm matching against is: ^\$\£?\d{0,10}(\.\d{2})?$ Here's how I think it should work (but clearly I'm wrong, because it does not actually work): ^\$\£?      

Pathological regular expression

2009-04-09 Thread David Liang
Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r'^(([^\\]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r'^(([^#]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-09 Thread David Liang
On Apr 9, 2:56 am, David Liang bmda...@gmail.com wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r'^(([^\\]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r

Re: Pathological regular expression

2009-04-09 Thread David Liang
On Apr 9, 2:56 am, David Liang bmda...@gmail.com wrote: Hi all, I'm having a weird problem with a regular expression (tested in 2.6 and 3.0): Basically, any of these: _re_comments = re.compile(r'^(([^\\]+|\\.|([^\\]+|\\.)*)*)#.*$') _re_comments = re.compile(r

[issue4958] email/header.py ecre regular expression issue

2009-03-27 Thread Amaury Forgeot d'Arc
Changes by Amaury Forgeot d'Arc amaur...@gmail.com: -- resolution: - duplicate status: open - closed superseder: - decode_header does not follow RFC 2047 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4958

Re: Regular expression bug?

2009-02-20 Thread Lie Ryan
On Thu, 19 Feb 2009 13:03:59 -0800, Ron Garret wrote: In article gnkdal$bcq$0...@news.t-online.com, Peter Otten __pete...@web.de wrote: Ron Garret wrote: I'm trying to split a CamelCase string into its constituent components. How about

Re: Regular expression bug?

2009-02-20 Thread umarpy
More elegant way [x for x in re.split('([A-Z]+[a-z]+)', a) if x ] ['foo', 'Bar', 'Baz'] R. On Feb 20, 2:03 pm, Lie Ryan lie.1...@gmail.com wrote: On Thu, 19 Feb 2009 13:03:59 -0800, Ron Garret wrote: In article gnkdal$bcq$0...@news.t-online.com,  Peter Otten __pete...@web.de wrote:

Regular expression bug?

2009-02-19 Thread Ron Garret
('((?=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: re.findall('(?=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems to be doing the Right Thing. Is this a bug in re.split, or am I missing something? (BTW, I tried looking

Re: Regular expression bug?

2009-02-19 Thread Albert Hopkins
On Thu, 2009-02-19 at 10:55 -0800, Ron Garret wrote: I'm trying to split a CamelCase string into its constituent components. This kind of works: re.split('[a-z][A-Z]', 'fooBarBaz') ['fo', 'a', 'az'] but it consumes the boundary characters. To fix this I tried using lookahead and

Re: Regular expression bug?

2009-02-19 Thread Kurt Smith
lookahead and lookbehind patterns instead, but it doesn't work: re.split('((?=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: re.findall('(?=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems to be doing the Right Thing

Re: Regular expression bug?

2009-02-19 Thread andrew cooke
work: re.split('((?=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: re.findall('(?=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems to be doing the Right Thing. Is this a bug in re.split, or am I missing something? (BTW, I

Re: Regular expression bug?

2009-02-19 Thread Peter Otten
. To fix this I tried using lookahead and lookbehind patterns instead, but it doesn't work: re.split('((?=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: re.findall('(?=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems

Re: Regular expression bug?

2009-02-19 Thread MRAB
work: re.split('((?=[a-z])(?=[A-Z]))', 'fooBarBaz') ['fooBarBaz'] However, it does seem to work with findall: re.findall('(?=[a-z])(?=[A-Z])', 'fooBarBaz') ['', ''] So the regular expression seems to be doing the Right Thing. Is this a bug in re.split, or am I missing something? (BTW

Re: Regular expression bug?

2009-02-19 Thread Ron Garret
') ['', ''] So the regular expression seems to be doing the Right Thing. Is this a bug in re.split, or am I missing something? (BTW, I tried looking at the source code for the re module, but I could not find the relevant code. re.split calls sre_compile.compile().split, but the string

Re: Regular expression bug?

2009-02-19 Thread Ron Garret
In article gnkdal$bcq$0...@news.t-online.com, Peter Otten __pete...@web.de wrote: Ron Garret wrote: I'm trying to split a CamelCase string into its constituent components. How about re.compile([A-Za-z][a-z]*).findall(fooBarBaz) ['foo', 'Bar', 'Baz'] That's very clever. Thanks!

Re: Regular expression bug?

2009-02-19 Thread Ron Garret
In article mailman.277.1235073073.11746.python-l...@python.org, andrew cooke and...@acooke.org wrote: i wonder what fraction of people posting with bug? in their titles here actually find bugs? IMHO it ought to be an invariant that len(r.split(s)) should always be one more than

Re: Regular expression bug?

2009-02-19 Thread Ron Garret
In article mailman.273.1235071607.11746.python-l...@python.org, Albert Hopkins mar...@letterboxes.org wrote: On Thu, 2009-02-19 at 10:55 -0800, Ron Garret wrote: I'm trying to split a CamelCase string into its constituent components. This kind of works: re.split('[a-z][A-Z]',

Re: Regular expression bug?

2009-02-19 Thread Steven D'Aprano
andrew cooke wrote: i wonder what fraction of people posting with bug? in their titles here actually find bugs? About 99.99%. Unfortunately, 99.98% have found bugs in their code, not in Python. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

[issue1566086] RE (regular expression) matching stuck in loop

2009-02-09 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: This problem has been addressed in issue #2636. Extra checks have been added to reduce the amount of backtracking. -- nosy: +mrabarnett ___ Python tracker rep...@bugs.python.org

[issue4958] email/header.py ecre regular expression issue

2009-02-03 Thread Tom Lynn
Tom Lynn tl...@users.sourceforge.net added the comment: Duplicates issue1047. -- nosy: +tlynn ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4958 ___

[issue4958] email/header.py ecre regular expression issue

2009-02-03 Thread Tom Lynn
Tom Lynn tl...@users.sourceforge.net added the comment: Oops, duplicates issue 1079 even. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4958 ___ ___

regular expression, help

2009-01-27 Thread Vincent Davis
I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line td colspan='2'Parcel ID: 39-034-15-009 /td I want to get the number

regular expression, help

2009-01-27 Thread Vincent Davis
I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help meI have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line td colspan='2'Parcel ID: 39-034-15-009 /td I want to get the number

Re: regular expression, help

2009-01-27 Thread Vincent Davis
is BeautifulSoup really better? Since I don't know either I would prefer to learn only one for now. Thanks Vincent Davis On Tue, Jan 27, 2009 at 10:39 AM, MRAB goo...@mrabarnett.plus.com wrote: Vincent Davis wrote: I think there are two parts to this question and I am sure lots I am

Re: regular expression, help

2009-01-27 Thread MRAB
Vincent Davis wrote: I think there are two parts to this question and I am sure lots I am missing. I am hoping an example will help me I have a html doc that I am trying to use regular expressions to get a value out of. here is an example or the line td colspan='2'Parcel ID: 39-034-15-009 /td

Regular expression that skips single line comments?

2009-01-19 Thread martinjamesevans
I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a semicolon. e.g. tests 1 and 2 should be ignored sInput = ; $1 test1

Re: Regular expression that skips single line comments?

2009-01-19 Thread MRAB
martinjamesev...@gmail.com wrote: I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a semicolon. e.g. tests 1 and 2

Re: Regular expression that skips single line comments?

2009-01-19 Thread Tim Chase
I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a semicolon. e.g. tests 1 and 2 should be ignored sInput = ; $1

Re: Regular expression that skips single line comments?

2009-01-19 Thread Casey
Another option (I cheated a little and turned sInput into a sequence of lines, similar to what you would get reading a text file): sInput = [ '; $1 test1', '; test2 $2', 'test3 ; $3 $3 $3', 'test4', '$5 test5', ' $6', ' test7 $7 test7', ] import re re_exp =

Re: Regular expression that skips single line comments?

2009-01-19 Thread Steven D'Aprano
On Mon, 19 Jan 2009 08:08:01 -0800, martinjamesevans wrote: I am trying to parse a set of files that have a simple syntax using RE. I'm interested in counting '$' expansions in the files, with one minor consideration. A line becomes a comment if the first non-white space character is a

Re: Regular expression that skips single line comments?

2009-01-19 Thread martinjamesevans
Firstly, a huge thanks to all for the solutions! Just what I was looking for. (Aside: why are you doing a case-insensitive match for a non-letter? Are there different upper- and lower-case dollar signs?) As you can probably imagine, I had simplified the problem slightly, the language uses

[issue4958] email/header.py ecre regular expression issue

2009-01-15 Thread Gabriel Genellina
Gabriel Genellina gagsl-...@yahoo.com.ar added the comment: Your example header is invalid. Excerpt from RFC2047 http:// www.ietf.org/rfc/rfc2047.txt section 5: + An 'encoded-word' MUST NOT be used in parameter of a MIME Content-Type or Content-Disposition field, or in any structured

Help with regular expression patterns

2008-11-28 Thread Michel Perez
Hi: i'm so newbie in python that i don't get the right idea about regular expressions. This is what i want to do: Extract using python some information and them replace this expresion for others, i use as a base the wikitext and this is what i do: code file=parse.py paragraphs = = Test

Re: how to get all repeated group with regular expression

2008-11-22 Thread MRAB
scsoce wrote: MRAB wrote: div class=moz-text-flowed style=font-family: -moz-fixedSteve Holden wrote: Please keep this on the list. scsoce wrote: Steve Holden wrote: scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', i

Re: Re: how to get all repeated group with regular expression

2008-11-22 Thread Jeremiah Dodds
On Fri, Nov 21, 2008 at 9:12 PM, scsoce [EMAIL PROTECTED] wrote: MRAB wrote: div class=moz-text-flowed style=font-family: -moz-fixedSteve Holden wrote: Please keep this on the list. scsoce wrote: Steve Holden wrote: scsoce wrote: say, when I try to search and match every char from

how to get all repeated group with regular expression

2008-11-21 Thread scsoce
say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall( r'(\d)*, '12346' ) , but only get '6' and Python doc indeed say: If a group is contained in a part of the pattern that matched multiple times, the last match is returned.

Re: how to get all repeated group with regular expression

2008-11-21 Thread Steve Holden
scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall( r'(\d)*, '12346' ) I think you will find you missed a quote out there. Always better to copy and paste ... , but only get '6' and Python doc indeed say: If

Re: how to get all repeated group with regular expression

2008-11-21 Thread Hrvoje Niksic
scsoce [EMAIL PROTECTED] writes: say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall( r'(\d)*, '12346' ) , but only get '6' and Python doc indeed say: If a group is contained in a part of the pattern that matched multiple

Re: how to get all repeated group with regular expression

2008-11-21 Thread Steve Holden
Please keep this on the list. scsoce wrote: Steve Holden wrote: scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall( r'(\d)*, '12346' ) I think you will find you missed a quote out there. Always

Re: how to get all repeated group with regular expression

2008-11-21 Thread M.-A. Lemburg
On 2008-11-21 15:31, scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', ??? That's a strange requirement. If you want to match every character, then why are you using a regular expression for this ? i tried re.findall( r'(\d

Re: how to get all repeated group with regular expression

2008-11-21 Thread MRAB
Steve Holden wrote: Please keep this on the list. scsoce wrote: Steve Holden wrote: scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall( r'(\d)*, '12346' ) I think you will find you missed a quote out

Re: Re: how to get all repeated group with regular expression

2008-11-21 Thread scsoce
MRAB wrote: div class=moz-text-flowed style=font-family: -moz-fixedSteve Holden wrote: Please keep this on the list. scsoce wrote: Steve Holden wrote: scsoce wrote: say, when I try to search and match every char from variable length string, such as string '123456', i tried re.findall(

Regular expression and exception

2008-11-15 Thread Mr . SpOOn
my code? Shall I figure out by myself? Apart from this, in a method I check valid strings with a regular expression. I pass the string to the method and then Ii have something like: m = re.match('[1-9]$', my_string) I was thinking to put a try except here, so that: try: m = re.match('[1-9

Re: Regular expression and exception

2008-11-15 Thread Arnaud Delobelle
: unsupported operand type(s) for +: 'int' and 'str' Ah, it's a TypeError! Apart from this, in a method I check valid strings with a regular expression. I pass the string to the method and then Ii have something like: m = re.match('[1-9]$', my_string) I was thinking to put a try except here, so

Re: Regular expression and exception

2008-11-15 Thread bearophileHUGS
Mr.SpOOn: try:     m = re.match('[1-9]$', my_string) except:     print 'something...' ... try:    m.group() except:    print 'error...' Generally don't write a nude except, use qualified exceptions, that is put there one of more exceptions that you want to catch (be careful with the

Re: Exact match with regular expression

2008-11-04 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Mr.SpOOn wrote: On Sat, Nov 1, 2008 at 1:57 AM, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: Funny how you never get a thank-you when you tell people to RTFM. My fault :\ I said thank you to Rob, but I just sent a private message. It's just that I did a

Re: Exact match with regular expression

2008-11-03 Thread Mr . SpOOn
On Sat, Nov 1, 2008 at 1:57 AM, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: In message [EMAIL PROTECTED], Rob Williscroft wrote: Read (and bookmark) this: http://www.python.org/doc/2.5.2/lib/re-syntax.html Funny how you never get a thank-you when you tell people to RTFM. My fault :\ I

Re: brackets content regular expression

2008-11-01 Thread netimen
aaa t bbb a tt š ff 2 ' In this case the regular expression is automatically greedy, matching the largest area possible. Note however that it won't work if you have something like this: first second. Matt As far as I know, you can't do that with a regular expressions

Re: Exact match with regular expression

2008-11-01 Thread Rob Williscroft
Lawrence D'Oliveiro wrote in news:[EMAIL PROTECTED] in comp.lang.python: In message [EMAIL PROTECTED], Rob Williscroft wrote: Read (and bookmark) this: http://www.python.org/doc/2.5.2/lib/re-syntax.html Funny how you never get a thank-you when you tell people to RTFM. Saying Thank

brackets content regular expression

2008-10-31 Thread netimen
I have a text containing brackets (or what is the correct term for ''?). I'd like to match text in the uppermost level of brackets. So, I have sth like: ' 123 1 aaa t bbb a tt ff 2 b'. How to match text between the uppermost brackets ( 1 aaa t bbb a tt ff 2 )? P.S. sorry

Re: brackets content regular expression

2008-10-31 Thread Alex_Gaynor
On Oct 31, 1:25 pm, netimen [EMAIL PROTECTED] wrote: I have a text containing brackets (or what is the correct term for ''?). I'd like to match text in the uppermost level of brackets. So, I have sth like: ' 123 1 aaa t bbb a tt   ff 2 b'. How to match text between the uppermost

Re: brackets content regular expression

2008-10-31 Thread Paul McGuire
On Oct 31, 12:25 pm, netimen [EMAIL PROTECTED] wrote: I have a text containing brackets (or what is the correct term for ''?). I'd like to match text in the uppermost level of brackets. So, I have sth like: ' 123 1 aaa t bbb a tt   ff 2 b'. How to match text between the

Re: brackets content regular expression

2008-10-31 Thread Matimus
) ' 1 aaa t bbb a tt ff 2 ' In this case the regular expression is automatically greedy, matching the largest area possible. Note however that it won't work if you have something like this: first second. Matt -- http://mail.python.org/mailman/listinfo/python-list

Re: brackets content regular expression

2008-10-31 Thread netimen
) m.group(1) ' 1 aaa t bbb a tt   ff 2 ' In this case the regular expression is automatically greedy, matching the largest area possible. Note however that it won't work if you have something like this: first second. Matt -- http://mail.python.org/mailman/listinfo/python-list

Re: brackets content regular expression

2008-10-31 Thread netimen
brackets. Anyway it should be easy to just match the outer most brackets: import re text = 123 1 aaa t bbb a tt š ff 2 r = re.compile((.+)) m = r.search(text) m.group(1) ' 1 aaa t bbb a tt š ff 2 ' In this case the regular expression is automatically greedy

Re: brackets content regular expression

2008-10-31 Thread bearophileHUGS
netimen: Thank's but if i have several top-level groups and want them match one by one: text = a b Ó d here starts a new group:   e f   g What other requirements do you have? If you list them all at once people will write you the code faster. bye, Bearophile --

Re: brackets content regular expression

2008-10-31 Thread Pierre Quentel
ff 2 ' In this case the regular expression is automatically greedy, matching the largest area possible. Note however that it won't work if you have something like this: first second. Matt Hi, Regular expressions or pyparsing might be overkill for this problem ; you can use

Re: brackets content regular expression

2008-10-31 Thread Matimus
t bbb a tt š ff 2 r = re.compile((.+)) m = r.search(text) m.group(1) ' 1 aaa t bbb a tt š ff 2 ' In this case the regular expression is automatically greedy, matching the largest area possible. Note however that it won't work if you have something like this: first second

Re: Exact match with regular expression

2008-10-31 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Rob Williscroft wrote: Read (and bookmark) this: http://www.python.org/doc/2.5.2/lib/re-syntax.html Funny how you never get a thank-you when you tell people to RTFM. -- http://mail.python.org/mailman/listinfo/python-list

Re: Exact match with regular expression

2008-10-31 Thread Shawn Milochik
On Fri, Oct 31, 2008 at 8:57 PM, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: In message [EMAIL PROTECTED], Rob Williscroft wrote: Read (and bookmark) this: http://www.python.org/doc/2.5.2/lib/re-syntax.html Funny how you never get a thank-you when you tell people to RTFM. --

[issue4219] Problem with regular expression

2008-10-28 Thread Carlos Eduardo Klock
Carlos Eduardo Klock [EMAIL PROTECTED] added the comment: Sorry, it is really a problem with the comma. Thanks for helping! :) ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4219 ___

[issue4219] Problem with regular expression

2008-10-28 Thread Georg Brandl
Changes by Georg Brandl [EMAIL PROTECTED]: -- status: open - closed ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4219 ___ ___ Python-bugs-list mailing

Exact match with regular expression

2008-10-26 Thread Mr . SpOOn
Hi, I'd like to use regular expressions to parse a string and accept only valid strings. What I mean is the possibility to check if the whole string matches the regex. So if I have: p = re.compile('a*b*') I can match this: 'aabbb' m = p.match('aabbb') m.group() 'aabbb' But I'd

<    5   6   7   8   9   10   11   12   13   14   >