我正在尝试从以下文本中提取 GMT 号码:
All times are GMT -3. The time now is 07:00 PM. Archive
我有代码:
data = "All times are GMT -3. The time now is 07:00 PM. Archive";
var myregex = /s\GMT([^"]*)./;
var matchArray = myregex.exec(data);
但是好像不行。在这个例子中,我试图将“-3”放入matchArray中,如何获取GMT之后空格之后和句点之前的字符串?谢谢!
最佳答案
您需要使用此正则表达式:
var matchArray = /\bGMT *([^.]+)/.exec(data);
if (matchArray)
console.log(matchArray[1]); //=> -3
关于JavaScript:提取与正则表达式匹配的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25274982/