starting from this kind of text;
var txt = "hello [a14] world, and [b74] some more [h85], ..."
I expect as result
var arr =
[ "hello "
, "[a14]"
, " world, and "
, "[b74]"
, " some more "
, "[h85]"
, ", ..."
]
what I have tried so far, but mastering regular expressions is still difficult for me...
let txt = "hello [a14] world, and [b74] some more [h85], ..."
let arr = txt.match(/(\[(.*?)\])|(.*?)/g)
console.log( arr )
.as-console-wrapper { max-height: 100% !important; top: 0; }