I'm searching for a regex that matches all words, but will give only one match.
What I have:
(.*\={1})\d+(\D*)
max. Money (EU)=600000 Euro
Euro
max. Money (EU)=600000 Euro plus 20000 for one person
=
=
Euro plus for one person
(\D+)
One cannot match discontinuous text with 1 match operation.
The easiest workaround is to capture the whole substring after =
+ number, and then remove numbers from the match with preg_replace('~\s*\d+~', '', $m[1])
.
See the PHP demo:
$re = '/=\d+\s*(.*)/';
$str = 'max. Money (EU)=600000 Euro plus 20000 for one person';
$res = '';
if (preg_match($re, $str, $m)) {
$res = preg_replace('~\s*\d+~', '', $m[1]);
}
echo $res; // => Euro plus for one person
Since you mention that a =
does not have to be followed by 1+ digits, you may really just explode
the string at the first =
and then remove digits in the second item:
$chunks = explode("=", $str, 2);
if (count($chunks) == 2) {
$res = preg_replace('~\s*\d+~', '', $chunks[1]);
}
See this PHP demo.