If there is no unsafe in sight, then the code is safe. Of course if there is an esoteric Pattern implementation, which is e.g. stateful, then it can pathologically return true when matched for the first time and then return false upon the second invocation. (So, to clarify: you are absolutely not allowed to rely on such behavior for memory safety of unsafe code.)
Why do you need this, though? Why don't you use strip_suffix()/strip_prefix()only, without checking for the match first?
Of course if there is an esoteric Pattern implementation, which is e.g. stateful, then it can pathologically return true when matched for the first time and then return false upon the second invocation.
Yes, of course Pattern implementation should (or, must) be consistent. However, there's no unsafes on my code, I don't have to worrying about that.
Why do you need this, though? Why don't you use strip_suffix() / strip_prefix()only , without checking for the match first?