This question already has answers here:
How do you access the matched groups in a JavaScript regular expression?
                                
                                    (18个回答)
                                
                        
                                2年前关闭。
            
                    
我有以下网址

https://website.com?id=XXXVVVCCCHHH


我只想要XXXVVVCCCHHH,我尝试了以下方法:

var phrase = 'https://website.com?id=XXXVVVCCCHHH';
var myRegexp = /id=(.*)/;
phrase = myRegexp.exec(phrase);


但这返回了:id=XXXVVVCCCHHH;

我如何编辑此内容以仅返回XXXVVVCCCHHH

最佳答案

只需使用split并采用第二个元素:



var url = "https://website.com?id=XXXVVVCCCHHH";
var part = url.split('=')[1];
console.log(part);

关于javascript - 将词组之后的所有内容返回到字符串末尾,不包括词组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46913403/

10-10 09:51