Re: How to print out html tags excluding the attributes

2019-07-22 Thread Rhodri James

On 21/07/2019 02:04, sum abiut wrote:

I want to use regular expression to print out the HTML tags excluding the
attributes.


That's a very good way of creating hard-to-read code and introducing 
subtle bugs and unexpected behaviours.  Try using an HTML parser like 
BeautifulSoup instead.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to print out html tags excluding the attributes

2019-07-21 Thread Michael F. Stemper
On 20/07/2019 20.04, sum abiut wrote:
> I want to use regular expression to print out the HTML tags excluding the
> attributes.
> 
> for example:
> 
> import re
> html = 'Hitest test'
> tags = re.findall(r'<[^>]+>', html)
> for a in tags:
> print(a)
> 
> 
> the output is :
> 
> 
> 
> 
> 
> 
> 
> 
> But I just want the tag, not the attributes

Try this:

for a in tags:
a = re.sub( " .*>", ">", a )
print(a)

(The two statements could be combined.)

-- 
Michael F. Stemper
Galatians 3:28
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to print out html tags excluding the attributes

2019-07-20 Thread Chris Angelico
On Sun, Jul 21, 2019 at 11:06 AM sum abiut  wrote:
>
> I want to use regular expression to print out the HTML tags excluding the
> attributes.

I'll just leave this here...

https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

No, I won't be that cruel. I'll also suggest that Beautiful Soup is an
excellent non-regex way to parse HTML.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


How to print out html tags excluding the attributes

2019-07-20 Thread sum abiut
I want to use regular expression to print out the HTML tags excluding the
attributes.

for example:

import re
html = 'Hitest test'
tags = re.findall(r'<[^>]+>', html)
for a in tags:
print(a)


the output is :








But I just want the tag, not the attributes







-- 
https://mail.python.org/mailman/listinfo/python-list