I am using a rather simple regex to make links posted to change that area to say [LINK REMOVED]. What I want to do though, is to completely clear out anything they typed with one space, instead of just removing the link itself.
I am not that good with regexes yet, so I could really use the help! Here’s what I have at the moment.
$comment = preg_replace('%[a-zA-Z0-9\-\.]+\.
(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)%', '[LINK REMOVED]', $comment);
You could either consume the whole comment in the match:
Or simply use
preg_matchand delete the comment yourself:Note that I also slightly optimized the regex by using the case-insensitive modifier
iand removing unnecessary escapes in the character class (for this to work, the hyphen has to be at the end of the character class though).