Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

meaning of `$/i` in regular expressions

Tags:

regex

php

What does the $/i mean in the following php code?

preg_match ('/^[A-Z \'.-]{2,20}$/i')
like image 674
php Avatar asked Dec 23 '22 04:12

php


2 Answers

/ denotes the end of the pattern. The i is a modifier that makes the pattern case-insensitive, and the $ anchor matches the end of the string.

like image 97
Sampson Avatar answered Jan 01 '23 20:01

Sampson


the $ is an anchor -- it means the end of the string should be there. the / is the end delimiter for the regular expression. The i means that the regular expressions should be case-insensitive (notice that [A-Z \'.-] only matches A-Z -- the i means it doesn't have to look for a-z as well).

like image 40
Carson Myers Avatar answered Jan 01 '23 20:01

Carson Myers