Following Regex:
(?<=href(\s+)?=(\s+)?")(?!(\s+)?http)(?!//).+(?=")
Works as expected with test articles:
href="//www.google-analytics.com/analytics.js">
href="https://www.google-analytics.com/analytics.js">
href="index.html">
href="..\index.html">
href="main.css">
href="..\assets\main.css">
href = " ..\assets\main.css ">
As you may see here: https://t.co/PC0U9br3vn
However:
[$string] $string = Get-Content sample.txt
[$string] $regex = '(?<=href(\s+)?=(\s+)?")(?!(\s+)?http)(?!(\s+)?//)(?!(\s+)?mailto).+(?=")'
$newString = $string -replace $regex, "..\$&"
$string
$newString
Produces the following output:
//www.google-analytics.com/analytics.js"> href=" https://www.google-analytics.com/analytics.js"> href="index.html"> href="..\index.html"> href=" main.css"> href="..\assets\main.css"> href = " ..\assets\main.css "> href = "mailto://email@domain "> href = "..\..\..\assets\main.css"
//www.google-analytics.com/analytics.js"> href=" https://www.google-analytics.com/analytics.js"> href="..\index.html"> href="..\index.html"> href=" main.css"> href="..\assets\main.css"> href = " ..\assets\main.css "> href = "mailto://email@domain "> href = "..\..\..\assets\main.css"
As only the first article is being operated on.
The same script is working elsewhere where the replace string does not utilise regex and is a simple string.