简体   繁体   中英

meaning of `$/i` in regular expressions

$/i在以下php代码中的含义是什么?

preg_match ('/^[A-Z \'.-]{2,20}$/i')

/ 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.

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 [AZ \\'.-] only matches AZ -- the i means it doesn't have to look for az as well).

Dollar sign is a common regex symbol meaning "end of line".

The slash at the end is the end of the expression itself.

Any letters after that slash are options you can turn on or off, called modifiers. In the case of i it means case-insensitive.

$ Matches at the end of the string the regex pattern is applied to. Matches a position rather than a character

/ is the ending delimiter of the regex pattern in PHP

i represents case insensitive regular expression search

you can also use this to understand things better, and can be used for testing/practice too.

http://gskinner.com/RegExr/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM