Javascript 使用正则表达式获取未包含在括号中的分号

Javascript 使用正则表达式获取未包含在括号中的分号,javascript,regex,Javascript,Regex,这是我的文本,如何使用RegExp获取不包含在括号中的分号 Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen Safari/538.2 LG Browser/7.00.00(LGE; 65UF8500-UB; 04.00.45; 1; DTV_W15U); webOS.TV-2015; LG NetCast.TV-2013 Compatible (LGE, 65UF8500-

这是我的文本,如何使用RegExp获取不包含在括号中的分号

Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen Safari/538.2 LG Browser/7.00.00(LGE; 65UF8500-UB; 04.00.45; 1; DTV_W15U); webOS.TV-2015; LG NetCast.TV-2013 Compatible (LGE, 65UF8500-UB, wireless)

您需要用空字符串替换括号。文本中有多个括号,因此最好使用非贪婪的正则表达式,如
\(.+?\)

非贪婪正则表达式选择尽可能小的块,而不是从第一个括号到最后一个括号进行选择

当文本中包含括号时,您可能会遇到问题,但我将尝试在中编辑它。

试试这个

var str = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen Safari/538.2 LG Browser/7.00.00(LGE; 65UF8500-UB; 04.00.45; 1; DTV_W15U); webOS.TV-2015; LG NetCast.TV-2013 Compatible (LGE, 65UF8500-UB, wireless)';
var regex = /\(.*?\)|([^\W_]+[^\s-]*)/g;
var arr = [];
var newstr = '';
var match = regex.exec(str);

while (match != null) {
    if( match[1] != null ) arr.push(match[1]);
    match = regex.exec(str);
}

if (arr.length > 0) {
   for (key in arr) newstr = newstr+ " " + arr[key];
}
console.log(newstr);

一个你想捕获什么的例子?我如何得到分号那些没有包含在paranthesis中的,请让我知道一个例子将有助于你从字符串中提取什么。但是我们如何通过使用regexh来做到这一点?我如何得到分号那些没有包含在paranthesis中的,请让我知道这是使用regex。如果你还想在括号后面加一个分号,那么你可以用
/\(.+?\)(;)?/g
谢谢你…但是我想得到分号,这个分号不包含在副词中。通过使用你的答案,我得到了副词中的分号。请检查一下once@reshma:你仍然可以用这个答案去掉括号,然后像平常一样解析分号。看看你的问题的编辑历史,看起来你一开始是想问分号,但它被其他人从你的标题中删掉了——可能是因为你标题的措词太草率了。请阅读,特别是其中的“拼写、语法和标点符号很重要!”即使英语不是你的第一语言,也要避免像12岁的孩子发短信一样说话。
var str = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/538.2 (KHTML, like Gecko) Large Screen Safari/538.2 LG Browser/7.00.00(LGE; 65UF8500-UB; 04.00.45; 1; DTV_W15U); webOS.TV-2015; LG NetCast.TV-2013 Compatible (LGE, 65UF8500-UB, wireless)';
var regex = /\(.*?\)|([^\W_]+[^\s-]*)/g;
var arr = [];
var newstr = '';
var match = regex.exec(str);

while (match != null) {
    if( match[1] != null ) arr.push(match[1]);
    match = regex.exec(str);
}

if (arr.length > 0) {
   for (key in arr) newstr = newstr+ " " + arr[key];
}
console.log(newstr);