草庐IT

preg-match

全部标签

php 从字符串中提取表情符号

我有一个包含表情符号的字符串。我想从该字符串中提取表情符号,我正在使用下面的代码,但它不是我想要的。$string="?helloworld?";preg_match('/([0-9#][\x{20E3}])|[\x{00ae}\x{00a9}\x{203C}\x{2047}\x{2048}\x{2049}\x{3030}\x{303D}\x{2139}\x{2122}\x{3297}\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{

php - 反转 "English"字造句

我有一个字符串,其中可能使用了多种语言,例如:اینمتنفارسیاستandthisis!!!inEnglishاینخطبعدیاستوthisisgoingtobecontinued...我只想反转英文单词,所以结果应该是这样的:اینمتنفارسیاستEnglishin!!!isthisandاینخطبعدیاستوcontinuedbetogoingisthis...对于要反转的文本,我得到:publicstaticfunctionreverseEnglishWords($string){returnpreg_replace_callback('/\w+/',func

php - 如何使用 PHP preg_replace 链接 Twitter 用户名?

我想搜索我的推特状态对象的文本属性并将@username换成@username.到目前为止我尝试过的是这样的:$pattern='/([@]{1})([a-zA-Z0-9\_]+)/';$replace='\1\2';$new_string=preg_replace($pattern,$replace,$text);但它不做任何替换。我知道我的regexp是错误的,但我无法弄清楚确切的位置/原因。帮忙?**编辑:...根据要求提供示例数据?$text='@janesmithIlikethat,butmyfriend@johndoesaiditbetter.';期望的输出:@janesm

php - ereg() 到 preg_match() 怎么样?

这个问题在这里已经有了答案:HowcanIconverteregexpressionstopreginPHP?(4个答案)关闭3年前。我正在使用一些简单的正则表达式。很简单:"user/""user/[A-z0-9_-]"这些都适用于ereg,但不适用于preg。如何转换?谢谢

php - preg_replace - 如何匹配任何不是\*\*的东西

我似乎无法找出正则表达式来匹配格式中的任何字符串**(anythingthat'snot**)**我试过在php中这样做$str="**helloworld*hello**";$str=preg_replace('/\*\*(([^\*][^\*]+))\*\*/s','$1',$str);但没有进行字符串替换。 最佳答案 您可以使用assertion?!与字符配对.占位符:=preg_replace('/\*\*(((?!\*\*).)+)\*\*/s',这基本上意味着匹配任意数量的任何东西(.)+,但是.永远不能占据\*\*的位

php - preg_replace 能否一次进行多个搜索和替换操作?

这是如何完成的,分几行://$strrepresentsstringthatneedscleaning:$str="Stringwithline\nbreakandtoomuchspaces";//Cleanstringwithpreg_replace():$str=preg_replace('/[\x00-\x09\x0B-\x1F\x7F]|^+|+$/','',$str);$str=preg_replace('/\x0A|+/','',$str);echo$str;//Output:"Stringwithlinebreakandtoomuchspaces"我的问题集中在将两个pr

php - 我如何在 PHP 中使用 "merge"这两个正则表达式?

我正在学习正则表达式,所以请放轻松!当不以_(下划线)开头并且包含仅单词字符(字母、数字和下划线本身)时,用户名被视为有效):namespaceGremo\ExtraValidationBundle\Validator\Constraints;useSymfony\Component\Validator\Constraint;useSymfony\Component\Validator\ConstraintValidator;classUsernameValidatorextendsConstraintValidator{publicfunctionvalidate($value,Co

php - preg_replace 模式和主题数组返回空数组

我想要一种从$keywords中删除$badwords元素的简单方法。我有什么(举个例子)$keywords=array('sebastian','nous','helene','lol');//itcouldbeanythinginfact$badwords=array('nous','lol','ene','seba');//arrayfullofstopwordsthatIwon'twritehere$filtered_keywords=array_filter(preg_replace($badwords,'',$keywords),'strlen');print_r($fil

php - 正则表达式获取前后N个词

我想获取给定搜索字符串的“上下文”。例如,对于以下行中的搜索字符串myselfMe,mydogandmyselfaregoingonavacation.我想得到dogandmyselfaregoingN=2。所以匹配前2个词和匹配后2个词。目前我像这样匹配整行:$lines=file($file->getFilename());$lines=preg_grep('/'.$_POST['query'].'/',$lines); 最佳答案 preg_grep()应该那样做,但听起来你需要preg_match()如果您可以在文本中有多个搜

php - 将多个匹配的正则表达式合并为一个并得到匹配的

我有一个正则表达式列表:suresnes|suresne|surenes|surenepommier|pommiers^musique$^(faq|aide)$^(file)?loss()?less$parisfaq我的用例是每个匹配的模式都会显示一个指向我的用户的链接,所以我可以有多个模式匹配。我针对一个简单的文本字符串“liveinparis”/“faq”/“pom”来测试这些模式...最简单的方法是用preg_match遍历所有模式,但我会在性能关键页面上经常这样做,所以这对我来说很糟糕。这是我尝试过的:将所有这些表达式与组名组合成一个:preg_match("@(?P^(faq