正则表达式,看一个特定的字母是否总是跟着另一个特定的字母

sam*_*sam -4 python regex

我有一个用户输入的单词.我想检查这个词是否符合以下规则.

规则:字母q总是用你写的.

user word : qeen
Run Code Online (Sandbox Code Playgroud)

输出将是

not match with the rule.
edited word : queen
Run Code Online (Sandbox Code Playgroud)

再举一个例子:

user word : queue
matched with rule. no edit required.
Run Code Online (Sandbox Code Playgroud)

Tim*_*ker 9

这非常适合前瞻性断言:

q(?=u)
Run Code Online (Sandbox Code Playgroud)

q只有当它跟随时才匹配u,而

q(?!u)
Run Code Online (Sandbox Code Playgroud)

q只有在没有后跟的情况下才匹配u.

所以:

>>> if re.search("q(?!u)", "qeen"):
...     print("q found without u!")
...
q found without u!
Run Code Online (Sandbox Code Playgroud)

要么

>>> re.sub("q(?!u)", "qu", "The queen qarreled with the king")
'The queen quarreled with the king'
Run Code Online (Sandbox Code Playgroud)

但是,一个字Iraq怎么样?