Regex cant match all data between repeated character

54 Views Asked by At

I wanted to match the data in between "@@@" characters

@@@haha@@@hoho@@@hehe@@@hihi@@@

regex:

@@@(.*?)@@@

By using this regex, I am only able to get haha and hehe, which are the 1st and 3rd matches. How to match all the 4 data in between @@@?

1

There are 1 best solutions below

0
On BEST ANSWER

Use look ahead to avoid that you grab the characters that you might still need to see in a next match:

@@@(.*?)(?=@@@)