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.
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html