Re: replace or regex

68 views
Skip to first unread message

Abdulkerim KELEŞ

unread,
Jun 28, 2012, 3:09:49 AM6/28/12
to django...@googlegroups.com
first is s='<ul>
   <li>A
     <ul>
         <li>B</li>
     </ul>
  </li>
</ul>'
s.replace('<ul>' ,' ', 1 ) 

but i dont remove last </ul> tag.

2012/6/28 pakyazilim <pakya...@gmail.com>
i have text ;
<ul>
   <li>A
     <ul>
         <li>B</li>
     </ul>
  </li>
</ul>

i want to remove first <ul> end for text end </ul> tag. 
how can i it?
thanks you...

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/lPA-eOEgEBYJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Kurtis Mullins

unread,
Jun 28, 2012, 10:19:06 AM6/28/12
to django...@googlegroups.com
You could use regular expressions to parse the string, break it up
into chunks and simply remove the first and last chunk (or whatever
you're looking for)
Also, you could use a DOM Parser to parse this tree and remove the
outer-most <ul>. Just make sure you don't remove the entire DOM Tree
within the UL.
I'd google around for ways to do either.

Tim Chase

unread,
Jun 28, 2012, 1:19:40 PM6/28/12
to django...@googlegroups.com, pakyazilim
On 06/28/12 01:42, pakyazilim wrote:
> i have text ;
> *<ul>*
> <li>A
> <ul>
> <li>B</li>
> </ul>
> </li>
> *</ul>*
> *
> *
> *i want to remove first <ul> end for text end </ul> tag. *
> *how can i it?*

Depends on what you want to happen in various odd edge-cases:

- what happens if other tags surround the outside <ul> block like

<foo><ul><li>A<ul><li>b</li></ul></li></ul></foo>

- what happens if there's only an opening or closing <ul> tag but
not the other?

- what happens if the <ul> tag has attributes on it like

<ul class='foo'>...</ul>

- what happens if case differs?

<UL>...</Ul>

- what happens if there are superfluous spaces?

< ul > ... < / ul >

- do you want to remove the tags and keep the whitespace around
them, or do you want to condense the whitespace too?


You likely want either a regexp or two, or you want a full-blown
HTML parser.

-tkc


Reply all
Reply to author
Forward
0 new messages