如何使用preg_match()来解决以下问题? [英] How to use preg_match() for the following problem?
本文介绍了如何使用preg_match()来解决以下问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用preg_match()将它与以特定字符串开头并以另一个特定字符串结尾的字符串进行比较,例如..Hello [some other text] Bye...它应该类似于preg_match(/ ^你好再见$ /,你好[其他一些文字]再见))。任何人都可以帮忙吗?
我尝试了什么:
i尝试过插入。但它只适用于Hello和Bye之间的一个字符
解决方案
/,你好[其他一些文字]再见))。任何人都可以帮忙吗?< br $> b $ b
我尝试了什么:
i试图插入。但它有效仅适用于Hello和Bye之间的一个字符
请参阅: PHP: PCRE模式 - 手册 [ ^ ]
特别是: PHP :重复 - 手动 [ ^ ]
// 如果是其他文字是可选的:
preg_match( / ^ Hello。* Bye
/, 你好[其他一些文字]再见))
// 如果需要其他文本:
preg_match( / ^你好。 +再见
how to use preg_match() to compare it with a string starting with a particular string and ending with another particular string eg .. "Hello[some other text]Bye" ... It should be something like preg_match("/^Hello Bye$/","Hello[some other text]Bye")) . Can any one help?
What I have tried:
i tried to insert . but it worked only for one character in between Hello and Bye
解决方案
/","Hello[some other text]Bye")) . Can any one help?
What I have tried:
i tried to insert . but it worked only for one character in between Hello and Bye
See: PHP: PCRE Patterns - Manual[^]
In particular: PHP: Repetition - Manual[^]
// If the other text is optional: preg_match("/^Hello.*Bye
/","Hello[some other text]Bye")) // If the other text is required: preg_match("/^Hello.+Bye
这篇关于如何使用preg_match()来解决以下问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文