For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
align upgradeprint(r0.group(1))
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera <[email protected]> wrote:
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
Not a bug. Find the longest possible match that fits this; as long as
you can find a space immediately after it, everything in between goes
into the .+ part.
If you want to exclude spaces, either use [^ ]+ or .+?.
On 2023-03-02 at 14:22:41 -0500,
jose isaias cabrera <[email protected]> wrote:
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
The bug is in your regular expression; the plus modifier is greedy.
If you want to match up to the first space, then you'll need something
like [^ ] (i.e., everything that isn't a space) instead of that dot.
align upgradeprint(r0.group(1))
On 3/2/23 12:28, Chris Angelico wrote:wrote:
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera <[email protected]>
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
Not a bug. Find the longest possible match that fits this; as long as
you can find a space immediately after it, everything in between goes
into the .+ part.
If you want to exclude spaces, either use [^ ]+ or .+?.
https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy
Noneprint(s0)
...s = "pn=jose pn=2017"
<re.Match object; span=(0, 15), match='pn=jose pn=2017'>s0 = r0.match(s)
s0
On 3/2/23 12:28, Chris Angelico wrote:wrote:
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera <[email protected]>
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
Not a bug. Find the longest possible match that fits this; as long as
you can find a space immediately after it, everything in between goes
into the .+ part.
If you want to exclude spaces, either use [^ ]+ or .+?.
https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy
Noneprint(s0)
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)
It is a well-known fact, Jose, that GIGO.
The letters "n" and "m" are not interchangeable. Your pattern fails because you have "pn" in one place and "pm" in the other.
...s = "pn=jose pn=2017"
<re.Match object; span=(0, 15), match='pn=jose pn=2017'>s0 = r0.match(s)
s0
-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=[email protected]> On Behalf Of jose isaias cabrera
Sent: Thursday, March 2, 2023 8:07 PM
To: Mats Wichmann <[email protected]>
Cc: [email protected]
Subject: Re: Regular Expression bug?
On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann <[email protected]> wrote:
On 3/2/23 12:28, Chris Angelico wrote:wrote:
On Fri, 3 Mar 2023 at 06:24, jose isaias cabrera <[email protected]>
Greetings.
For the RegExp Gurus, consider the following python3 code:
<code>
import re
s = "pn=align upgrade sd=2023-02-"
ro = re.compile(r"pn=(.+) ")
r0=ro.match(s)
align upgradeprint(r0.group(1))
</code>
This is wrong. It should be 'align' because the group only goes up-to
the space. Thoughts? Thanks.
Not a bug. Find the longest possible match that fits this; as long as
you can find a space immediately after it, everything in between goes into the .+ part.
If you want to exclude spaces, either use [^ ]+ or .+?.
https://docs.python.org/3/howto/regex.html#greedy-versus-non-greedy
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)
Noneprint(s0)
Any help is appreciated.
--
https://mail.python.org/mailman/listinfo/python-list
On 02Mar2023 20:06, jose isaias cabrera <[email protected]> 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 r0.search(s).
- Cameron Simpson <[email protected]>
jose isaias cabrera <[email protected]> writes:
On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann <[email protected]> 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)
>>> print(s0)
None
Assuming that you were expecting to match "pn=2017", then you probably
don't want the 'match' method. Read its documentation. Then read the documentation for the _other_ methods that a Pattern supports. Then you
will be enlightened.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (0 / 16) |
| Uptime: | 167:50:50 |
| Calls: | 12,096 |
| Calls today: | 4 |
| Files: | 15,003 |
| Messages: | 6,517,819 |