<p>I'm trying to fetch some HTML from various blogs and have noticed that different providers use the same tag in different ways.</p>

<p>For example, here are two major providers that use the meta name generator tag differently:</p>

<ul>
<li>Blogger: <code>&lt;meta content='blogger' name='generator'/&gt;</code> (content first, name later and, yes, single quotes!)  </li>
<li>WordPress: <code>&lt;meta name="generator" content="WordPress.com" /&gt;</code> (name first, content later)</li>
</ul>

<p>Is there a way to extract the value of content for all cases (single/double quotes, first/last in the row)?</p>

<p>P.S. Although I'm using Java, the answer would probably help more people if it where for regular expressions generally.</p>

[{'answer_id': 31538, 'author': 'Sergio Acosta', 'author_id': 2954, 'author_profile': 'https://Stackoverflow.com/users/2954', 'pm_score': 2, 'selected': False, 'text': "<p>Those differences are not really important according to the XHTML standard.</p>\n\n<p>In other words, they are exactly the same thing.</p>\n\n<p>Also, if you replace double quotes with single quotes would be the same.</p>\n\n<p>The typical way of 'normalizing' an xml document is to pare it using some API that treats the document as its Infoset representation. Both DOM and SAX style APIs work that way.</p>\n\n<p>If you want to parse them by hand (or with a RegEx) you have to replicate all those things in your code and, in my opinion, that's not practical.</p>\n"}, {'answer_id': 31543, 'author': 'martinatime', 'author_id': 1353, 'author_profile': 'https://Stackoverflow.com/users/1353', 'pm_score': 2, 'selected': False, 'text': '<p>Actually, you should probably use some sort of HTML parser where you can inspect each node (and therefore node attributes) in the DOM of the page. I\'ve not used any of these for a while so I don\'t know the pros and cons but here\'s a list <a href="http://java-source.net/open-source/html-parsers" rel="nofollow noreferrer">http://java-source.net/open-source/html-parsers</a> </p>\n'}, {'answer_id': 31546, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 5, 'selected': True, 'text': "<p>The answer is: <strong>don't use regular expressions</strong>.</p>\n\n<p>Seriously. Use a SGML parser, or an XML parser if you happen to know it's valid XML (probably almost never true). You will absolutely screw up and waste tons of time trying to get it right. Just use what's already available.</p>\n"}, {'answer_id': 31574, 'author': 'Grey Panther', 'author_id': 1265, 'author_profile': 'https://Stackoverflow.com/users/1265', 'pm_score': 2, 'selected': False, 'text': '<p>Note: single quotes (even no quotes, if the value doesn\'t contain a space) is valid according to <a href="http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.2.2" rel="nofollow noreferrer">the W3C HTML spec</a>. Quote:</p>\n\n<blockquote>\n  <p>By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39)... In certain cases, authors may specify the value of an attribute without any quotation marks.</p>\n</blockquote>\n\n<p>Also, don\'t forget that the order of attributes can be reversed and that other attributes can appear in the tag.</p>\n'}, {'answer_id': 31595, 'author': 'martinatime', 'author_id': 1353, 'author_profile': 'https://Stackoverflow.com/users/1353', 'pm_score': 0, 'selected': False, 'text': '<p>Ok, since you are looking for language-agnostic then you can try a REGEX like <code>/&lt;meta\\s.*content=.*&gt;/</code> and take the result from that and parse out the specific values that you are looking for. I\'m by no means a REGEX expert so there is probably a better way but in using the tool at <a href="http://www.codehouse.com/webmaster_tools/regex/" rel="nofollow noreferrer">http://www.codehouse.com/webmaster_tools/regex/</a> I matched both of the strings you provided.</p>\n'}, {'answer_id': 31601, 'author': 'Preston', 'author_id': 2006, 'author_profile': 'https://Stackoverflow.com/users/2006', 'pm_score': 1, 'selected': False, 'text': '<p>You may want to give Java\'s <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/HTMLEditorKit.html" rel="nofollow noreferrer">HTMLEditorKit</a> a shot. It is easy to experiment with to see if the parsing provides what you are looking for. </p>\n'}, {'answer_id': 31622, 'author': 'dwestbrook', 'author_id': 3119, 'author_profile': 'https://Stackoverflow.com/users/3119', 'pm_score': 0, 'selected': False, 'text': '<p>If you must use regex, here is a regex to get just the content part:</p>\n\n<pre><code>content\\s*=\\s*[\'"].*?[\'"]\n</code></pre>\n\n<p>returns</p>\n\n<pre><code>content = "blogger"\n</code></pre>\n\n<p>and</p>\n\n<pre><code>content=\'Worpress.com\'\n</code></pre>\n\n<p>respectively. I\'m no regex expert, but it gets those when given your examples in <a href="http://regexpal.com/" rel="nofollow noreferrer">regexpal</a>.</p>\n\n<p>Once you get that you can get everything between the quotes however you choose, be it another regex (which is just immoral at that point) or just looping over the characters.</p>\n'}, {'answer_id': 32141, 'author': 'Peter Stuifzand', 'author_id': 1633, 'author_profile': 'https://Stackoverflow.com/users/1633', 'pm_score': 0, 'selected': False, 'text': '<p>If your using java you may want to look at <a href="http://tagsoup.info" rel="nofollow noreferrer">tagsoup</a>, which is a SAX-compliant parser for "[parsing] HTML as it is found in the wild".</p>\n'}]
['https://Stackoverflow.com/questions/31535', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2644/']