为什么在PHP的preg_match中在模式的前后添加正斜杠?

为什么在PHP的preg_match中在模式的前后添加正斜杠?,php,regex,preg-match,Php,Regex,Preg Match,有人知道为什么我们要在PHP中的preg_match方法中在模式的前后添加正斜杠吗 preg_match('/test/', "Welcome to testing world"); 另外,如何将它们动态添加到模式中?分隔符是一个特殊字符,用于在表达式的开头和结尾表示表达式的哪一部分。这允许您使用修饰符和解释器来了解哪些是表达式,哪些是修饰符 例如: preg_match('/Test/', "Welcome to testing world"); //nothing found preg_m

有人知道为什么我们要在PHP中的preg_match方法中在模式的前后添加正斜杠吗

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

另外,如何将它们动态添加到模式中?

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

例如:

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

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

例如:

preg_match('/Test/', "Welcome to testing world"); //nothing found
preg_match('/Test/i', "Welcome to testing world"); //i -> case-insensitive search, all ok
简单:
$pattern=“test”;preg_match(“/$pattern/”,“欢迎来到测试世界”)简单:
$pattern=“test”;preg_match(“/$pattern/”,“欢迎来到测试世界”)