Answer the question
In order to leave comments, you need to log in
How to write a regular expression with replacement?
It is necessary to leave only emails like [mailto:[email protected] [email protected]], how to do it?
$str = "
[email protected]
[mailto:[email protected] [email protected]]
";
$target_str = " (?!\[mailto\:)([a-z0-9._%+-][email protected](?:[A-Z0-9-]+\.)+[A-Z]{2,}(?!\]))(?!\])";
$replacement_str = " [mailto:$1 $1]";
$num_matches = 0;
$str2 = preg_replace( '/' . $target_str . '/ui', $replacement_str, $str , -1, $num_matches );
echo $str;
echo $str2;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question