Python3 正则表达式不适用于脚本,但适用于 pythex.org

Python3 regular expression not working on script, but works on pythex.org

我正在 Python3 中编写脚本,我想使用正则表达式。我有一些 utf-8 编码的文件用作我的主脚本的配置文件。

我想更改其中的一些行(经典配置更改)。

我的代码,仍然处于 poc 状态,是这样的:

regex = re.compile('^SHOW_ALL\s[^:]')
with open('./config.txt', encoding='utf-8', mode='r+') as old_file:
    for line in old_file.read():
            if regex.match(line):
                print(line)

config.txt 是这样的:

#Κάτι στα ελληνικά

SHOW_ALL OFF 15
PRINT ON
SHOW_VALUES O

COM 0
PRINTER_NAME samsung_not_a_real_name
CAMERA 33

我在 pythex.org 检查了我的正则表达式,它似乎工作正常。

可能出了什么问题?

*link 重定向到我在 regex.org

尝试过的确切正则表达式和文本

尝试用old_file.readLines();

替换old_file.read();