Home  >  Article  >  Backend Development  >  php正则表达

php正则表达

WBOY
WBOYOriginal
2016-06-23 14:03:33745browse

怎么写一个正则,同时匹配两种标签
$pattern="#(\)#U";
$pattern="#(\.*\)#U";
像上面两,分别匹配了input和select。如何把它们合并成一个,只要满足其中一种都行。因为需要按照标签的顺序输出,所以不能分成两次来匹配


回复讨论(解决方案)

$str = '<input type="text" name="lname" />';  $str .= '<select><option value ="volvo">Volvo</option><option value ="saab">Saab</option><option value="opel">Opel</option><option value="audi">Audi</option></select>';preg_match_all("#((\<input.*\>)|(\<select.*\>.*\<\/select\>))#U",$str,$out);var_dump($out);


这样可否?

正则里有或‘|’这个操作符

PHP code?123456$str = '';  $str .= '

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn