I want to detect things that start with @ and have a double bracket. @[uuid][displayValue]. I have the following regex for that.
@\[([^\][]*)]\[([^\][]*)]
I want to pair lookahead((?=) with it but doing that does not work.
(?=@\[([^\][]*)]\[([^\][]*)])
It does not return any match. Lookahead is to keep delimiter in javascript split function.
Consider the following example:
const text = 'I want to thank @[handle1][displayValue1], @[handle2][displayValue2] for their contribution'.
When I use text.split(/(?=@\[([^\][]*)]\[([^\][]*)])/g) with the regex, I am looking for following output
['I want to thank ','@[handle1][displayValue1]',', ','@[handle2][displayValue2],'for their contribution']
run the sniipet, and you get the matches with start indexes
for( let a of 'I want to thank @[handle1][displayValue1], @[handle2][displayValue2] for their contribution'.matchAll(/@\[(.*?)\]\[(.*?)\]/g)){console.log(a)}
if uuid/displayValue might contain @[][] like words, you will need to code more logic, probably with a finite state machine