简体   繁体   English

正则表达式PHP子模式

[英]Regex PHP sub pattern

I can't get a sub pattern to work 我无法使用子模式

preg_match_all("/<title>(\b\w{4,100}\b)<\/title>/", $input_lines, $output_array);

I want to extract all the words from a title attribute which have more than 3 characters. 我想从具有超过3个字符的title属性中提取所有单词。

If I try the following expressions they both work. 如果我尝试以下表达式,它们都可以工作。 But as soon i want to put the last one as a sub pattern it doesn't output anything but 2 empty records in the array. 但是,只要我想将最后一个作为子模式,它就不会在数组中输出2条空记录。

preg_match_all("/<title>(.*)<\/title>/", $input_lines, $output_array);

preg_match_all("/\b\w{4,100}\b/", $input_lines, $output_array);

I'm using the following text an $input_lines 我正在使用以下文本$ input_lines

<title>This is a big test</title>

This is a two-step operation. 这是一个两步操作。 First extract the title, then get the words. 首先提取标题,然后得到单词。

if( preg_match("(<title>(.*?)</title>)i",$input_lines,$match)) {
    $title = $match[1];
    preg_match_all("/\w{4,}/",$title,$matches);
    $words = $matches[0];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM