Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 9:56 PM Alan Bawden wrote: > > jose isaias cabrera writes: > >On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > >This re is a bit different than the one I am used. So, I am trying to match >everything after 'pn=': > >import re >s = "pm=jose

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
ject manager. pn=project name. I needed search() rather than match(). > > >>> s = "pn=jose pn=2017" > ... > >>> s0 = r0.match(s) > >>> s0 > > > > > -Original Message- > From: Python-list On > Behalf Of jose isaias cab

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 8:30 PM Cameron Simpson wrote: > > On 02Mar2023 20:06, jose isaias cabrera wrote: > >This re is a bit different than the one I am used. So, I am trying to > >match > >everything after 'pn=': > > > >import re > >s = "pm=jose pn=2017" > >m0 = r"pn=(.+)" > >r0 =

Re: Regular Expression bug?

2023-03-02 Thread Alan Bawden
jose isaias cabrera writes: On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s)

Re: Regular Expression bug?

2023-03-02 Thread Cameron Simpson
On 02Mar2023 20:06, jose isaias cabrera wrote: This re is a bit different than the one I am used. So, I am trying to match everything after 'pn=': import re s = "pm=jose pn=2017" m0 = r"pn=(.+)" r0 = re.compile(m0) s0 = r0.match(s) `match()` matches at the start of the string. You want

RE: Regular Expression bug?

2023-03-02 Thread avi.e.gross
;> s0 -Original Message- From: Python-list On Behalf Of jose isaias cabrera Sent: Thursday, March 2, 2023 8:07 PM To: Mats Wichmann Cc: python-list@python.org Subject: Re: Regular Expression bug? On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > > On 3/2/23 12:28

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote: > > On 3/2/23 12:28, Chris Angelico wrote: > > On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > >> > >> Greetings. > >> > >> For the RegExp Gurus, consider the following python3 code: > >> > >> import re > >> s = "pn=align upgrade

RE: Regular Expression bug?

2023-03-02 Thread avi.e.gross
José, Matching can be greedy. Did it match to the last space? What you want is a pattern that matches anything except a space (or whitespace) followed b matching a space or something similar. Or use a construct that makes matching non-greedy. Avi -Original Message- From: Python-list

Re: Regular Expression bug?

2023-03-02 Thread jose isaias cabrera
On Thu, Mar 2, 2023 at 2:32 PM <2qdxy4rzwzuui...@potatochowder.com> wrote: > > On 2023-03-02 at 14:22:41 -0500, > jose isaias cabrera wrote: > > > For the RegExp Gurus, consider the following python3 code: > > > > import re > > s = "pn=align upgrade sd=2023-02-" > > ro = re.compile(r"pn=(.+) ")

Re: Regular Expression bug?

2023-03-02 Thread Mats Wichmann
On 3/2/23 12:28, Chris Angelico wrote: On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: Greetings. For the RegExp Gurus, consider the following python3 code: import re s = "pn=align upgrade sd=2023-02-" ro = re.compile(r"pn=(.+) ") r0=ro.match(s) print(r0.group(1)) align upgrade

Re: Regular Expression bug?

2023-03-02 Thread 2QdxY4RzWzUUiLuE
On 2023-03-02 at 14:22:41 -0500, jose isaias cabrera wrote: > For the RegExp Gurus, consider the following python3 code: > > import re > s = "pn=align upgrade sd=2023-02-" > ro = re.compile(r"pn=(.+) ") > r0=ro.match(s) > >>> print(r0.group(1)) > align upgrade > > > This is wrong. It should

Re: Regular Expression bug?

2023-03-02 Thread Chris Angelico
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera wrote: > > Greetings. > > For the RegExp Gurus, consider the following python3 code: > > import re > s = "pn=align upgrade sd=2023-02-" > ro = re.compile(r"pn=(.+) ") > r0=ro.match(s) > >>> print(r0.group(1)) > align upgrade > > > This is wrong.

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:

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
On Thu, Feb 19, 2009 at 12:55 PM, Ron Garret rnospa...@flownet.com 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

Re: Regular expression bug?

2009-02-19 Thread andrew cooke
i wonder what fraction of people posting with bug? in their titles here actually find bugs? anyway, how about: re.findall('[A-Z]?[a-z]*', 'fooBarBaz') or re.findall('([A-Z][a-z]*|[a-z]+)', 'fooBarBaz') (you have to specify what you're matching and lookahead/back doesn't do that). andrew

Re: Regular expression bug?

2009-02-19 Thread Peter Otten
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'] This kind of works: re.split('[a-z][A-Z]', 'fooBarBaz') ['fo', 'a', 'az'] but it consumes the boundary characters.

Re: Regular expression bug?

2009-02-19 Thread MRAB
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 lookbehind patterns instead, but it doesn't

Re: Regular expression bug?

2009-02-19 Thread Ron Garret
In article mailman.281.1235073821.11746.python-l...@python.org, MRAB goo...@mrabarnett.plus.com wrote: 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

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