正则表达式和正斜杠 [英] regular expression and forward slash

查看:441
本文介绍了正则表达式和正斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过正则表达式搜索字符串中的关键字.它适用于所有关键字,例如其中一个包含正斜杠的关键字"time/emit".

i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" .

即使使用preg_quote($find,'/')进行了转义,我仍然收到消息:

Even using preg_quote($find,'/'), which escapes it, i still get the message:

Unknown modifier 't' in /frontend.functions.php  on line 71

如果我打印查找图案,它会显示/time\\/emit/.如果没有preg_quote,则显示/time/emit/,并且都返回相同的错误消息.

If i print the find pattern, it shows /time\\/emit/ . Without preg_quote, it shows /time/emit/ and both return the same error message.

任何知识都是有用的.

推荐答案

尝试以与/

我个人使用`

我见过人们在使用#

我认为大多数字符都很好.您可以在此处了解更多信息: http://pl.php.net /manual/zh-CN/regexp.reference.delimiters.php

I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php

喜欢这个:

 preg_match('#time/emit#', $subject);  // instead of /time/emit/

换句话说:您的$find变量应该包含/time/emit/

To put it another way: Your $find variable should contain rather #time/emit# than /time/emit/

这篇关于正则表达式和正斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆