Find text javascript

前端 未结 7 1176
醉话见心
醉话见心 2021-01-26 16:32

I Have string random length

Ex:

 sadsadsadsad(323213)dfsssds

 sadsadsadsad(321)dfsssds

How can I find the values in brackets?.

<
相关标签:
7条回答
  • 2021-01-26 17:18

    Try by using the following code it will helps you if you have remove nested Parentheses example "a(bcdefghijkl(mno)p)q"

    function removeParentheses(s) {
        let openPatterns = [];
        for(let i=0; i < s.length; i++){
    
            if(s[i] == '('){
                openPatterns.push(i);
            }
    
            if(s[i] == ')'){
                const lastIndexOpen = openPatterns.pop();
                const originalTxt = s.slice(lastIndexOpen ,i+1);
                //here you have the raw text      
                const rawText = s.slice(lastIndexOpen+1,i);
                //this code works to remove the parentesis 
                //s= s.replace(originalTxt, reverseTxt);
                //i-=2;
            }
        }
        return rawText;    
    }
    
    0 讨论(0)
提交回复
热议问题