How does a regular expression find the value of a particular condition?

problem description:
how do I use regular expressions to find values in parentheses that begin with a colon (including colons, values are not limited to numbers)?

example: match (: 123)

  ((:123))
  (((:123)))

always keep the parentheses at the previous level, and do not replace the content if the parentheses do not contain colons. Thank you!


': (: 12345),: (: 1),: (12345),: (:),: (), '.match (/\ (:\ d +\) / g) .map (v = > v.slice)
select the one that meets the requirements. Then delete the unwanted parentheses. Started using grouping. But it doesn't work.
clipboard.png



':(:12345):(:abc),:(:abc:sv),:(:abc):asd),:(:1),:(12345),:(:),:(),'.match(/\(:[a-z0-9]+\)/gi).map(v=>v.slice(1,-1))

/\(:[a-z0-9]+\)/gi [a-z0-9]

clipboard.png


"/\ (:. +?\) / g"
gets the value in parentheses, you can use capture "/\ ((:. +?\) / g" , $1 is the result


var str='lsdk(:)sjdflkf(:sdkfjl)(:lskdf)sldkf:(jsklf)';
var regex=/\((:.*?)\)/g;
var result=[];
var matchStr=null;
while((matchStr=regex.exec(str))!=null){
    result.push(matchStr[1]);
}

how does the regular expression find the value of a specific condition?


let text = '(:12345)'
text.replace(/.*?\((:.+)\).*/, '$1')
Menu