-1

I am using the following regex

'/\@(.*)\((.*)\)/'

And I am trying to get @ONE(TWO) one and two from the expression. Which works as long as it's the only time that it can be found before an end of line (I think)

I am quite green with regex and I really cannot understand what I am doing wrong.

What I need is to be able to get all the ONE/TWO couples. Can you please help me.

I am working with PHP and the following function

$parsed_string = preg_replace_callback(
    // Placeholder for not previously created article
    // Pattern example: @George Ioannidis(person)             
    '/\@(.*)\((.*)\)/', 
    function ($matches) {
        return $this->parsePlaceholders( $matches );
    },
    $string
);

The results I am getting from https://regexr.com The results I am getting from https://regexr.com/

1 Answers1

1

* expression is greedy by default. For example such regexp (.*)a will return you bdeabde result on bdeabdea string. You should use special ? symbol for non-greedy * behavior. In your case try to use /\@(.*?)\((.*?)\)/ regexp.

Ivan Kalita
  • 2,197
  • 1
  • 18
  • 31