RegEx to return 'href' attribute of 'link' tags only?
Im trying to craft a regex that only returns <link> tag hrefs Why does this regex return all hrefs including <a hrefs? (?<=<link\s+.*?)href\s*=\s*[\'\"][^\'\"]+ <link rel="stylesheet" rev="stylesheet" href="idlecore-tidied.css?T_2_5_0_228" media="screen"> <a href="anotherurl">Slash Boxes</a> thank you Either /(?<=<link\b[^<>]*?)\bhref=\s*=\s*(?:"[^"]*"|'[^']'|\S+)/ or /<link\b[^<>]*?\b(href=\s*=\s*(?:"[^"]*"|'[^']'|\S+))/ The main difference is [^<>]*? instead of .*? . This is because you don't want it to continue the search into other tags. Avoid lookbehind for such simple case, just match