I’m trying to get an HTML source code meta tag “name” attribute value in a single regular expression. Is this possible?
Right now I’m running a regular expression to get all meta tags:
"<meta.*?>"
I’m storing all matches into a List<String>, and then I run a second regular expression on those results to get the “name” attribute value:
"name=\".*?\""
Is there a way of doing this with a single regular expression? I just want to store the “name” attribute ONLY of meta tags, ignoring other HTML tags.
Thanks!
Your list (matchList ) in the end should contain the desired result which will be the values of all name attributes.
Finally as you will see in all posts related with xml/html and regexes the norm is to go for a parser instead of a regex. However if you task is so simple you can do it with a regex easily.