$re = '/(?:\buser1\b)?(.+?)(?:\buser1\b|$)/m';
$str = 'I don\'t get how to create a regular expression that matches everything, except a fixed, single word. Can somebody help me?
Background: alias map for mailserver which redirects all mail to one user. /.*/ -> user1 produces a redirection loop, so i need to exclude user1 from the regexp.
Edit:
The regex should match everything, EXCEPT the single word user1. It should also match input that contains that word, i.e., user11.
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php