So I have a select element with options of different timezones, see the exampel below.
<option value="2.0">(GMT +2:00) Kaliningrad, South Africa</option>
I want to replace everything after (GMT +2:00)
to "Local time".
I came up with this regexp below but it only matches (GMT +2:00)
, I want to target and change the rest of the string. And maybe I should also be using replace() insted.
var matches = $(this).html().matc开发者_Python百科h(/\(GMT [+-][0-9]+:00\)/);
console.log(matches);
Try this:
var finalString = $(this).html().replace(/(\(GMT [+-][0-9]+:00\))(.*)/, "$1 Local Time");
Working example: http://jsfiddle.net/r65Hp/
$('select.whatever option').text(function(i, text) {
return text.replace(/\).*?$/, ') Local Time');
});
jsFiddle.
精彩评论