halliewuud
halliewuud

Reputation: 2785

regexp get what is left after the match

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

Answers (2)

alex
alex

Reputation: 490153

$('select.whatever option').text(function(i, text) {   
  return text.replace(/\).*?$/, ') Local Time');
});

jsFiddle.

Upvotes: 1

Chandu
Chandu

Reputation: 82893

Try this:

var finalString = $(this).html().replace(/(\(GMT [+-][0-9]+:00\))(.*)/, "$1 Local Time");

Working example: http://jsfiddle.net/r65Hp/

Upvotes: 2

Related Questions