Issue 36058: Improve file decoding before re.search

Spin-off from #14929, which fixed crash.  From msg161754:
"The default extension is .py. The default encoding for .py files is utf-8. I think that is the default for what Idle writes. So I think this should be the default encoding (explicitly given) at least for .py files.
From msg161755: (but not sure about this)
"Also, perhaps dialog box could have encodings field. People should be able to grep python code for any legal identifier, and this means proper decoding according to the encoding they actually use."