Re: Regular Expressions: Can't quite figure this problem out

2007-09-26 Thread Robert Dailey
Even better! Now I can drop the regular expression that did the same thing :) Thanks! On 9/26/07, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > Robert Dailey wrote: > > > Hmm, ElementTree.tostring() also adds a space between the last character > > of the element name and the />. Not sure why it is

Re: Regular Expressions: Can't quite figure this problem out

2007-09-26 Thread Fredrik Lundh
Robert Dailey wrote: > Hmm, ElementTree.tostring() also adds a space between the last character > of the element name and the />. Not sure why it is doing this. ET is commonly used to generate (X)HTML fragments, and that space provides partial HTML compatibility. since the default serializer n

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Gabriel Genellina
En Tue, 25 Sep 2007 18:21:08 -0300, Robert Dailey <[EMAIL PROTECTED]> escribi�: > One thing I noticed is that it is placing an arbitrary space between " > and > />. For example: > > > > > Notice that there's a space between "image" and /> Just remove the space in the replacement string: >>

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
On 9/25/07, J. Cliff Dyer <[EMAIL PROTECTED]> wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Robert Dailey top posted: > > Hmm, ElementTree.tostring() also adds a space between the last > > character of the element name and the />. Not sure why it is doing > > this. > > > > Somethin

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Hmm, ElementTree.tostring() also adds a space between the last character of the element name and the />. Not sure why it is doing this. Something like will become after the tostring(). On 9/25/07, Robert Dailey <[EMAIL PROTECTED]> wrote: > > One thing I noticed is that it is placing an arbitrar

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
One thing I noticed is that it is placing an arbitrary space between " and />. For example: Notice that there's a space between "image" and /> Any way to fix this? Thanks. On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PR

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Miles
On 9/25/07, Paul McGuire wrote: > On Sep 24, 11:23 pm, Gabriel Genellina wrote: > > py> print re.sub(r"<(\w+)([^>]*)>", r"<\1\2 />", source) > > And let's hope the OP doesn't have to parse anything truly nasty like: > > esolang:language> Or something mildly nasty, like -Miles -- http://mail.py

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Fortunately I don't have any XML that complex, however you make a good point. On 9/25/07, Paul McGuire <[EMAIL PROTECTED]> wrote: > > On Sep 24, 11:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: > > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]> > > escribi?: > > >

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Paul McGuire
On Sep 24, 11:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]> > escribi?: > > > What I meant was that it's not an option because I'm trying to learn > > regular > > expressions. RE is just as built in as anything else

Re: Regular Expressions: Can't quite figure this problem out

2007-09-25 Thread Robert Dailey
Awesome description. This was more than helpful. I'm really grateful that you took the time to outline that for me. I really understand it now. However, as I mentioned in the lxml mailing list, I'm starting to learn more towards regular expressions being a very LAST resort to solving problems like

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Gabriel Genellina
En Mon, 24 Sep 2007 23:51:57 -0300, Robert Dailey <[EMAIL PROTECTED]> escribi�: > What I meant was that it's not an option because I'm trying to learn > regular > expressions. RE is just as built in as anything else. Ok, let's analyze what you want. You have for instance this text: "" which s

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Steve Holden
Robert Dailey wrote: > What I meant was that it's not an option because I'm trying to learn > regular expressions. RE is just as built in as anything else. > > On 9/24/07, *Steve Holden * <[EMAIL PROTECTED] > > wrote: > > Robert Dailey wrote: > > > > >

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
What I meant was that it's not an option because I'm trying to learn regular expressions. RE is just as built in as anything else. On 9/24/07, Steve Holden <[EMAIL PROTECTED]> wrote: > > Robert Dailey wrote: > > > > > > On 9/24/07, *Gabriel Genellina* <[EMAIL PROTECTED] > >

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Gabriel Genellina
En Mon, 24 Sep 2007 23:17:59 -0300, Robert Dailey <[EMAIL PROTECTED]> escribi�: > On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: >> >> Yes: forget about regular expressions. ElementTree does that for free: > > That's not an option. Ok, keep fighting with REs - good luck! -- Gabriel

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Steve Holden
Robert Dailey wrote: > > > On 9/24/07, *Gabriel Genellina* <[EMAIL PROTECTED] > > wrote: > > Yes: forget about regular expressions. ElementTree does that for free: > > > That's not an option. > Even though it's built into Python 2.5? That's a strange requirement

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
On 9/24/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > > Yes: forget about regular expressions. ElementTree does that for free: > That's not an option. -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Gabriel Genellina
En Mon, 24 Sep 2007 22:53:57 -0300, Robert Dailey <[EMAIL PROTECTED]> escribi�: > Any easier way to do a 'replace' then using start(), end(), and slicing > operations? I'm currently doing it manually. Yes: forget about regular expressions. ElementTree does that for free: source = """ """

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
Thanks. Any easier way to do a 'replace' then using start(), end(), and slicing operations? I'm currently doing it manually. On 9/24/07, Miles <[EMAIL PROTECTED]> wrote: > > On 9/24/07, Robert Dailey <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I'm attempting to create a regular expression that rem

Re: Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Miles
On 9/24/07, Robert Dailey <[EMAIL PROTECTED]> wrote: > Hi, > > I'm attempting to create a regular expression that removes redundancy in > empty XML elements. For example: > > > > The regular expression would convert the XML above into: > > If you can guarantee that the XML is well-formed, then

Regular Expressions: Can't quite figure this problem out

2007-09-24 Thread Robert Dailey
Hi, I'm attempting to create a regular expression that removes redundancy in empty XML elements. For example: The regular expression would convert the XML above into: And another complex example: would be: So far I've been unsuccessful in creating a regular expression to do this. Belo