In other words may one use /<tag[^>]*>.*?<\/tag>/
regex to match the tag
html element which does not contain nested tag
elements?
For example (lt.html):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>greater than sign in attribute value</title>
</head>
<body>
<div>1</div>
<div title=">">2</div>
</body>
</html>
Regex:
$ perl -nE"say $1 if m~<div[^>]*>(.*?)</div>~" lt.html
And screen-scraper:
#!/usr/bin/env python
import sys
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(sys.stdin)
for div in soup.findAll('div'):
print div.string
$ python lt.py <lt.html
Both give the same output:
1
">2
Expected output:
1
2
w3c says:
Attribute values are a mixture of text and character references, except with the additional restriction that the text cannot contain an ambiguous ampersand.