0

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.

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.

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

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

1 Answer 1

4

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];
}
Sign up to request clarification or add additional context in comments.

2 Comments

@true Thank you for being my... uh... "outburst controller" XD
You're a hero! Was hoping to do it with one step, but looks like that was impossible. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.