Paul McGuire wrote:
On Mar 27, 5:19 am, Tim Chase wrote:
>>> import re
>>> s = """a=1,b="0234,)#($)@", k="7" """
>>> rx = re.compile(r'[ ]*(\w+)=([^",]+|"[^"]*")[ ]*(?:,|$)')
>>> rx.findall(s)
[('a', '1'), ('b', '"0234,)#($)@"'), ('k', '"7"')]
>>> rx.findall('a=1, *DODGY*SYNTAX* b=2')
[(
On Mar 27, 5:19 am, Tim Chase wrote:
> >> >>> import re
> >> >>> s = """a=1,b="0234,)#($)@", k="7" """
> >> >>> rx = re.compile(r'[ ]*(\w+)=([^",]+|"[^"]*")[ ]*(?:,|$)')
> >> >>> rx.findall(s)
> >> [('a', '1'), ('b', '"0234,)#($)@"'), ('k', '"7"')]
> >> >>> rx.findall('a=1, *DODGY*SYNTAX* b=
On Mar 27, 9:19 pm, Tim Chase wrote:
> >> >>> import re
> >> >>> s = """a=1,b="0234,)#($)@", k="7" """
> >> >>> rx = re.compile(r'[ ]*(\w+)=([^",]+|"[^"]*")[ ]*(?:,|$)')
> >> >>> rx.findall(s)
> >> [('a', '1'), ('b', '"0234,)#($)@"'), ('k', '"7"')]
> >> >>> rx.findall('a=1, *DODGY*SYNTAX* b=
>>> import re
>>> s = """a=1,b="0234,)#($)@", k="7" """
>>> rx = re.compile(r'[ ]*(\w+)=([^",]+|"[^"]*")[ ]*(?:,|$)')
>>> rx.findall(s)
[('a', '1'), ('b', '"0234,)#($)@"'), ('k', '"7"')]
>>> rx.findall('a=1, *DODGY*SYNTAX* b=2')
[('a', '1'), ('b', '2')]
>>>
I'm going to save this one and
Paul McGuire wrote:
> On Mar 26, 2:51 pm, "R. David Murray" wrote:
> > OK, I've got a little problem that I'd like to ask the assembled minds
> > for help with. I can write code to parse this, but I'm thinking it may
> > be possible to do it with regexes. My regex foo isn't that good, so if
> >
John Machin wrote:
> On Mar 27, 6:51 am, "R. David Murray" wrote:
> > OK, I've got a little problem that I'd like to ask the assembled minds
> > for help with. I can write code to parse this, but I'm thinking it may
> > be possible to do it with regexes. My regex foo isn't that good, so if
> >
On Mar 27, 8:43 am, Terry Reedy wrote:
> R. David Murray wrote:
> > OK, I've got a little problem that I'd like to ask the assembled minds
> > for help with. I can write code to parse this, but I'm thinking it may
> > be possible to do it with regexes. My regex foo isn't that good, so if
> > any
R. David Murray wrote:
OK, I've got a little problem that I'd like to ask the assembled minds
for help with. I can write code to parse this, but I'm thinking it may
be possible to do it with regexes. My regex foo isn't that good, so if
anyone is willing to help (or offer an alternate parsing su
R. David Murray wrote:
Tim Chase wrote:
r = re.compile(r"""
(\w+)
\s*=\s*(
"(?:[^"]*)"
|
[^,]+
)
""", re.VERBOSE)
results = [
(m.group(1), m.group(2).strip('"'))
for m in r.finditer(s)
]
Thank you thank you. I owe you a dinner if we are
On Mar 26, 2:51 pm, "R. David Murray" wrote:
> OK, I've got a little problem that I'd like to ask the assembled minds
> for help with. I can write code to parse this, but I'm thinking it may
> be possible to do it with regexes. My regex foo isn't that good, so if
> anyone is willing to help (or
On 2009-03-26, R. David Murray wrote:
> Tim Chase wrote:
>>r = re.compile(r"""
>> (\w+)
>> \s*=\s*(
>> "(?:[^"]*)"
>> |
>> [^,]+
>> )
>> """, re.VERBOSE)
>>results = [
>> (m.group(1), m.group(2).strip('"'))
>> for m in r.finditer(s)
>> ]
>
Tim Chase wrote:
>r = re.compile(r"""
> (\w+)
> \s*=\s*(
> "(?:[^"]*)"
> |
> [^,]+
> )
> """, re.VERBOSE)
>results = [
> (m.group(1), m.group(2).strip('"'))
> for m in r.finditer(s)
> ]
>
> Things like internal quoting ('b="123\"456", c="1
On Mar 27, 6:51 am, "R. David Murray" wrote:
> OK, I've got a little problem that I'd like to ask the assembled minds
> for help with. I can write code to parse this, but I'm thinking it may
> be possible to do it with regexes. My regex foo isn't that good, so if
> anyone is willing to help (or
The challenge is to turn a string like this:
a=1,b="0234,)#($)@", k="7"
into this:
[("a", "1"), ("b", "0234,)#($)#"), ("k", "7")]
A couple solutions "work" for various pathological cases of input
data:
import re
s = 'a=1,b="0234,)#($)@", k="7"'
r = re.compile(r"""
(?P\w+)
14 matches
Mail list logo