Q:

Regex to get string between two characters

I want to get everything between [ and ] like:
[hello] hi

should give:
hello

I tried \[(.*)\] but when i use:
[hello] hi [yo]

it gives:
hello] hi [yo

How can i make it so that it returns only the first one, then the second one like hello and yo

A:

\[(.*)\] is greedy meaning the * matches until the last occurance. Use a ? and it will stop at the first.
\[(.*?)\]

Demo: https://regex101.com/r/cM6aD7/1
PreDemo: https://regex101.com/r/cM6aD7/2

