I have a regex
$pattern = '/\b\d{4}-\d{4}\b/';
preg_match($pattern, $text, $matches);
I need to get the 5 words after that regex. Any ideas how I would accomplish this?
For example ” Power Slot Slotted Rotors – 1997-1998 Oldsmobile Regency – Brakes & Brake Pads – Brake Rotors.”
I need to return “1997-1998 Oldsmobile Regency – Brakes &”;
Any ideas?
// Update from the bottom comments.
There might be multiple matches in one string. For instance
“For example:”2000-2009 Ford Explorer, 2000-2010 Ford Ranger. 1674SJT JBA Cat4ward Headers Features”
I’m still trying to get the 1st 5 “non white spaces” after the number sequence xxxx-xxxx.
Following your edits, try this:
See it working
With thanks to @Ariel for the regex this is based on, which was correct until additional requirements were specified through edits. If you like this, go upvote that answer as well 😉