Q:

Searching for a specific string of text, then replacing the string

I have a PHP file with content similar to this:
<table class="select_descript" cellspacing="4" cellpadding="0" border="0" align="center" valign="middle"><tbody><tr><td>Top songs for the past week. Updated Saturday, 21 March 2015</td></tr></tbody></table>

I have the date in there, I want to be able to replace this date section only in this PHP file with the current date. I'm thinking of making use of finding both valign="middle"><tbody><tr><td> and the word Updated and use a -replace method. 
$phpfile = phpfile.php
(Get-Content $phpfile) -replace "(?<=Updated ).+","Updated (Get-Date).ToLongDateString()"

But I am stuck with the expression.

A:

You don't say under what circumstances the file is being changed.  My first suggestion is to create a source template file with a unique token where the current date goes.
...<td>Top songs for the past week. Updated [[DATE_HERE]]</td>...

Then the replacement is straightforward and mostly foolproof.
(gc template.php) -replace '[[DATE_HERE]]',(Get-Date).ToLongDateString() | sc $phpfile

For the regex solution, you need the string that identifies the location but is least likely to change. I wouldn't try to parse based on the HTML tags, or a change in formatting will break your regex.  In your example I would use the whole "Top songs ..." text.
$searchText = 'Top songs for the past week. Updated [^<]*'
$replaceText = "Top songs for the past week. Updated $((Get-Date).TolongDateString())"

(Get-Content $phpfile -Raw) -replace $searchText,$replaceText | Set-Content $phpfile

Note that the -Raw parameter to Get-Content causes it to read the whole file at once and then close the file so that you don't get an error when you pass the same filename to Set-Content.

