Find text javascript

前端 未结 7 1196
醉话见心
醉话见心 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:14

    You can use indexOf and substring

    let str = 'sadsadsadsad(321)dfsssds';
    
    let getFirstIndex = str.indexOf('(');
    let getSecondIndex = str.indexOf(')');
    
    let subStr = str.substring(getFirstIndex + 1, getSecondIndex);
    console.log(subStr)

提交回复
热议问题