string between parentheses with regex

This question already has an answer here:

  • How do you access the matched groups in a JavaScript regular expression? 14 answers

  • 你需要使用捕获正则表达式组()来分别提取数字和字符串,看看:

    let rawStr = "this is (131PS) for now";
    
    let theMatch = rawStr.match(/((d+)([A-Z]+))/);
    
    if (theMatch) {
      let theNum = parseInt(theMatch[1]);
      let theString = theMatch[2];
      
      console.log(theNum, theString);
    }
    链接地址: http://www.djcxy.com/p/76802.html

    上一篇: 如何只用正则表达式提取匹配的字符串的一部分?

    下一篇: 括号与正则表达式之间的字符串