Get text between two rounded brackets

后端 未结 5 1518
小蘑菇
小蘑菇 2020-11-29 08:19

How can I retrieve the word my from between the two rounded brackets in the following sentence using a regex in JavaScript?

\"This is (my

5条回答
  •  庸人自扰
    2020-11-29 08:25

    You may also try a non-regex method (of course if there are multiple such brackets, it will eventually need looping, or regex)

    init = txt.indexOf('(');
    fin = txt.indexOf(')');
    console.log(txt.substr(init+1,fin-init-1))
    

提交回复
热议问题