Q: Regex - Get matches of @[SomeText] in a string I want to get all matches of @[SomeText] pattern in a string.
For example, for this string:
here is @[text1] some text @[text2]
I want @[text1] and @[text2].
I'm using Regex Hero to check my pattern matching online,
and my pattern works fine when there's one expression to match,
For example:
here is @[text1] text

but with more then one, I get both matches with the text in the middle.

This is my regex:
@\[.*\]

I would appreciate assistance in isolating the occurrences.

A: The problem here is that you are using greedy quantifier (*). To capture all you need, you should use lazy quantifier (*?) with a global modifier:
/(@\[.*?\])/g

Take a look here https://regex101.com/r/pH0gA5/1

A: This should work  :
@\[(.*?)\]

Details :
(.*?) : match everything in a non-greedy way and capture it.
Because the *? quantifier is lazy (non-greedy), it matches as few characters as possible to allow the overall match attempt to succeed, i.e. text1. For the match attempt that starts at a given position, a lazy quantifier gives you the shortest match. 

A: .* is greedy by default, so it only finds one match, treating "text1] and @[text2" as the text between the two square brackets.
If you add a questions mark after the .* then it will find the minimum number of characters before reaching a ].
So the regex \@[.*?] do what you want.
