<?php $words = array("man", "map", "php", "pop", "pnp"); $patterns = array("ma?", "p?p"); foreach ($patterns as $pattern) { $regex = '\b(' . str_replace('?', '.', $pattern) . ')\b'; $count = preg_match_all("/$regex/", implode('-', $words), $matches); echo "$pattern matched $count times on " . implode(',', $matches[1]) . ".\n"; }
You have javascript disabled. You will not be able to edit any code.