femotizo
femotizo

Reputation: 1415

PHP Regex to match multiline

i need to build a pattern to match a multiline code

    $data['infos'] = array();
    foreach ($infos as $info) {
        $data['infos'][] = array(
            'title' => $special['title'],
            'text'  => $special['summary'],,
        );
    }
    $data['next'] = $this->url('page/next');
    $data['page'] = $this->url('page/curent');

my attempt was to use (\$data\['infos']\[] = array\(\n).*\n\t.*\n\t*\)\; but it did not work, but when i tried (\$data\['infos']\[] = array\() only this part was match

$data['infos'][] = array(

how do i build the pattern to match this part only

        $data['infos'][] = array(
            'title' => $special['title'],
            'text'  => $special['summary'],,
        );

also i love to see it simple so that i can modify it for other similar case.have been on it for a whole day with no luck, kindly help me out.

Thanks in advance.

Upvotes: 0

Views: 538

Answers (1)

bobble bubble
bobble bubble

Reputation: 18555

If a simple pattern would be sufficient depends on how your input could look like.

$re = '~\Q$data[\'infos\'][]\E.*?\);~s';
  • \Q...\E is used to match literally (also could escape the brackets/dollar).
  • .*? in single line mode (s flag) matches lazily any amount of any character.

See demo at regex101 or php demo at eval.in

Upvotes: 1

Related Questions