What is the meaning of $ 1 and $ 2 in the Blade :: extend function

I saw this example in Laravel Docs :

Blade::extend(function($view, $compiler) { $pattern = $compiler->createMatcher('datetime'); return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/YH:i\'); ?>', $view); }); 

but I don't seem to understand this, and for a while, examples on the Internet include $ 3.

I did not find the right answer to this question through a Google search, I appreciate any help.

+5
source share
1 answer

This is a replacement string! It replaces the variable (e.g. $1 ) with the corresponding template group!

As an example (Pseudocode):

 $pattern = "/(.*?)([az])/"; //Here is $1 ^ This group and $2 would be the second group 

As well as additional help:

PHP regex Cheat Sheet

Regex Online Tester (<- It perfectly displays the correspondence of your regular expression and explains the different parts of your regular expression)

+5
source

Source: https://habr.com/ru/post/1211514/


All Articles