I am trying to use REGEX in order to find out if a certain tag is found inside the source code of a website.
The tag definitely starts with "<link" and definitely ends with ">". There are some strings that need to be found between these two delimiters in order to "succeed":
- 'rel="alternate"'
- 'media='
- 'max-width:'
- '640px'
- 'only screen'
- 'href='
Within the source code of a website this should match for example the following tag:
The problem is, that the elements within this tag can be in a different sequence like for example:
< link media="only screen and (max-width: 640px)" rel="alternate" href="http://m.example.com/page-1">
or:
< link href="http://m.example.com/page-1" media="only screen and (max-width: 640px)" rel="alternate"/>
My problem is, that using a REGEX formula like
(<link ).*(rel=).*(media=).*(640px).*(href=).*(>)
would need rel, media, 640px and href to be in exactly this order, but it is also possible that the order is completely another way around.
What I did so far:
- searching through Stackoverflow (it was probably asked before - but I couldn't find the solution. The former asker probably did use very differents wording when describing)
- try building the formula on https://regex101.com (this way I came up with what I have so far)
Can anyone push me in the right direction please? Thank you in advance to everyone!