KGF
KGF

Reputation: 13

PHP preg_match only one match

I have had some problems using preg_match, Instead of selecting 1 thing. It finds from the start of the first, to the end of the last.

preg_match('/@section\(\'(.*)\'\)(.*)@endsection/s', $content,$results

$Content :

@section('title')

Number 1

@endsection

@section('content')

Number 2

@endsection

But when i use the preg_match, the result comes out like :

Number 1

@endsection

@section('content')

Number 2

Upvotes: 1

Views: 220

Answers (1)

Narendrasingh Sisodia
Narendrasingh Sisodia

Reputation: 21437

You are looking for non-greedy quantifier over here like as

/@section\(\'(.*?)\'\)(.*?)@endsection/s
              //^^      ^^

Regex

Upvotes: 2

Related Questions