Aah, here comes on of the most beautiful features about JScript's replace function: you can use a regular expression combined with a custom replacement handler function!
First of all, you need to put what you want to find between parentheses in your regular expression. This way, the engine will capture these parts and pass them as parameters to your replace function or as properties of the global RegExp object (e.g. RegExp.$1). This will give you almost infinite control about how the replacing is done since you can do anything inside your handler, and it is something I use a lot in my scripts too.
Here is your code adapted with String.replace. As you can see, I got rid of your for-loop (in fact, you were better off with a while-loop there) and I made an example replacement handler function.
js code:
sentenceT = sentenceT.replace(
/\[t=(.+)\](.*?)\[\/t\]/gi, //The regular expression, note the parentheses to capture parts of our interest
function(sMatch, $1, $2, nOffset, sFull) { //We can use a function to do the replacing!
if($1 === "ps") {
//We found a [t=ps] match
Time = $2; //Set the Time variable to what's between the tags
return ""; //Return an empty string to remove this match from the result
}
//Return the matched piece untouched if nothing was recognized
return sMatch;
}
);
Of course, if you have for instance 3 capture parts in your regular expression, you should place 3 receiving parameters in your handler function. Alternatively, you can leave out the last parameters (nOffset and sFull) if you don't need them.