Fix `file.sed` state to use sed to check 'before' pattern

Fixes #4425
Fixes #3342

Added the `file.sed_contains` function to the `file` module (courtesy of @whiteinge).  The `file.sed` state now uses this function to check for the `before` pattern.  This makes it so the `file.sed` state now should support basically any sed syntax, including named backreferences, the ignore case `i` flag, and uses the `limit` argument when checking the `before` pattern.

Should fix most of the outstanding issues around the `file.sed` state.