开发者

regexp get what is left after the match

开发者 https://www.devze.com 2023-04-01 22:31 出处:网络
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>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消