I am reading a text file that looks like
<tr><td>W543562</td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td>W543563</td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td>W543564</td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td>W543565</td><td>OPEN</td><td>003</td><td>4</td></tr>
</tbody></table></div></div></body></html>
I am specifically interested in the W#. I want to grab the number, then write back to the text file to make it look like this to turn it into a hyperlink
<tr><td><a href="https://www.website.com/Order=W543562">W543562</a></td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td><a href="https://www.website.com/Order=W543563">W543563</a></td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td><a href="https://www.website.com/Order=W543564">W543564</a></td><td>OPEN</td><td>003</td><td>4</td></tr>
<tr><td><a href="https://www.website.com/Order=W543565">W543565</a></td><td>OPEN</td><td>003</td><td>4</td></tr>
</tbody></table></div></div></body></html>
What I have is
$text = [IO.File]::ReadAllText("C:\Temp\parse3.txt")
$url = "https://www.website.com/=W"
$Matches = [regex]::matches($text, "<td>W([\s\S]*?)</td>")
foreach ($match in $Matches)
{
Write-Output $match.Groups[1].Value.Trim();
}
Which pulls the W# and displays it on each line, but I need to store each one into a variable and then use it to write back to each line and concatenate the $url
Ideally if I can cut the code down to something like Select-String "<td>W-</td>" | Add-Content $url+w#
that would be great. But as far as I can tell, Select-String
does not lend itself to selecting characters between others and trimming the beginning and end off. Much less find a specific range of dynamic characters.
Any ideas?