javascript - regex include text inside brackets -
i want alert text inside brackets. can when have square brackets.
= "1[the]" words = a.match(/[^[\]]+(?=])/g); alert(words); but can't going round brackets ()
i have tried few different things don't quite have head around need change here.
= "1(the)" words = a.match(/(^[\])+(?=])/g); alert(words); = "1(the)" words = a.match(/[^(\)]+(?=])/g); alert(words); = "1(the)" words = a.match(/[^[\]]+(?=))/g); alert(words); = "1(the)" words = a.match(/[^[\]]+(?=])/g); alert(words); where going wrong?
you current regex doesn't technically words inside brackets. example, if string "foobar)" match "foobar".
try like:
a = "1(the) foo(bar)" regexp = /\((.*?)\)/g // loop through matches match = regexp.exec(a) while (match != null) { alert(match[1]) # match[1] captured group 1 match = regexp.exec(a) }
Comments
Post a Comment