I have currently a set of seds that's working well except for one thing.The particular expression I'm having an issue with is:sed -i '/[^}.to]\.to[[:space:]]/ s/\(\S\)/expect(\1/' ../_spec_seded/$fileRight now this works fine.Basically it looks for .to and insert expect at the start of the expression.In particular, it excludes }.to when looking to match on .to which works.Now I want to also exclude 'this' or 'that' from the search match.  In my case }.to or end.toi.e. instead of/[^}.to]\.to[[:space]]/should I have:/[^}.to|^end\.to]\.to[[:space]]//[^}.to][^end\.to]\.to[[:space]]//[(^}.to|end\.to)]\.to[[:space]]//[^(}.to|end\.to)]\.to[[:space]]/would I even need to escape parens if using them like/[^\(}.to|end\.to\)]\.to[[:space]]/or even the | as well?/[^\(}.to\|end\.to\)]\.to[[:space]]/I'm trying to make the match work on:stuff.to do thingstuff).to do thingthis.to thatall.all.all.to dopretend.do  # Note this edge case! (pretend contains end!) but not onthis will be here }.to dolast.end}.to doall.this at the end.tonone at allend.toandall.this at the end.to # i.e. no spaces before as it is the start of the line.Negating with OR's generally (all languages) seems tricky (due to false positives).
sed - how to exclude multiple patterns in the match
sed;regular expression
Pending your response to my comment on the question, here's my answer:First of all, [^}.to] doesn't do what you seem to think. It will not match lines that don't have the pattern }.to. It matches lines that have any character other than ., }, t or o. In other words, many lines.To make things easier, let's have sed print nothing by default then tell it to print everything except those lines matching the patterns you want to exclude:sed -n '/\(\bend\|}\.to\)/!p' your_fileThis will print all lines not containing end.to at a word boundary (i.e. allend.to doesn't count) or }.to.If, in addition you want to print only those lines that match \.foo[[:space:]], simply delete lines matching unwanted patterns and add a conditional print:sed -n '/\(\bend\|}\.to\)/d;/\.to[[:space:]]/p' your_fileOf course, between the match and the print, you can apply whatever substitution you feel like:sed -n '/\(\bend\|}\.to\)/d;/\.to[[:space:]]/s/foo/bar/g;p' your_file