Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the difference between $1 and \1 in regex?

I wanted to know what is the difference between \1 and $1 in regex PHP because in every strings that I checked, they were the same and when I searched about it, there wasn’t any good resources or explanations about this issue.

For example:

preg_replace("/([a-z0-9]+)/","$1",$string) 
//returns the same as preg_replace("/([a-z0-9]+)/","\1",$string)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no difference, other than preference, according to the PHP documentation.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading