为什么在PHP的preg_match中在模式的正面和背面添加正斜杠?

时间:2016-06-01 06:10:10

标签: php regex preg-match

有谁知道为什么我们在PHP的 preg_match 方法中在模式的正面和背面添加正斜杠?

preg_match('/test/', "Welcome to testing world");

还有如何动态添加到模式?

1 个答案:

答案 0 :(得分:2)

分隔符是在表达式的开头和结尾使用的特殊字符,用于表示哪个部分是表达式。这允许您使用修饰符和解释器来知道哪个是表达式,哪个是修饰符。

示例:

preg_match('/Test/', "Welcome to testing world"); //nothing found
preg_match('/Test/i', "Welcome to testing world"); //i -> case-insensitive search, all ok