How to extract text in square brackets from string in JavaScript? -


how can extract text between pairs of square brackets string "[a][b][c][d][e]", can following results:

array: ["a", "b", "c", "d", "e"]

string: "abcde"

i have tried following regular expressions, no avail:

(?<=\[)(.*?)(?=\])

\[(.*?)\]

i don't know text expecting in string of array, example you've given.

var arrstr = "[a][b][c][d][e]"; var arr = arrstr.match(/[a-z]/g) --> [ 'a', 'b', 'c', 'd', 'e' ] typeof 'array'  can use `.concat()` on produced array combine them string. 

if you're expecting multiple characters between square brackets, regex can (/[a-z]+/g) or tweaked liking.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -