Reputation: 2785
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().match(/\(GMT [+-][0-9]+:00\)/);
console.log(matches);
Upvotes: 1
Views: 241
Reputation: 490153
$('select.whatever option').text(function(i, text) {
return text.replace(/\).*?$/, ') Local Time');
});
Upvotes: 1
Reputation: 82893
Try this:
var finalString = $(this).html().replace(/(\(GMT [+-][0-9]+:00\))(.*)/, "$1 Local Time");
Working example: http://jsfiddle.net/r65Hp/
Upvotes: 2