[英]How to perform multiple search using php regex?
preg_match("/Designer:(.*?)|Created by:(.*?)\n/i",$sitesource,$designer);
Hi, Can anyone tell me how can I perform multiple searches?嗨,谁能告诉我如何执行多个搜索? For example, if the "designer" keyword not found, then search for "created by" and so on
例如,如果没有找到“设计师”关键字,则搜索“创建者”等
You can use您可以使用
preg_match_all("/(?:Created by|Designer):(.*)/i", $sitesource, $designer);
That is, use preg_match_all
to match multiple occurrences and merge the two alternatives into a simpler (?:Created by|Designer):(.*)
that means也就是说,使用
preg_match_all
匹配多个匹配项并将两个备选方案合并为一个更简单的(?:Created by|Designer):(.*)
,这意味着
(?:Created by|Designer)
- either Created by
or Designer
(?:Created by|Designer)
- Created by
或Designer
:
- a colon :
- 一个冒号(.*)
- capturing group #1: the rest of the line. (.*)
- 捕获组 #1:该行的 rest。 See the regex demo .请参阅正则表达式演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.