我正在尝试编写一个正则表达式,在点之前和之后添加一个空格。但是,我只希望在点后有空格或行尾时出现此情况。
但是,对于行尾情况,我无法这样做。
Eg.
I want a hotel. >> I want a hotel .
my email is zob@gmail.com >> my email is zob@gmail.com
I have to play. bye! >> I have to play . bye!
Run Code Online (Sandbox Code Playgroud)
以下是我的代码:
# If "Dot and space" after word or number put space before and after
utterance = re.sub(r'(?<=[a-z0-9])[.][ $]',' . ',utterance)
Run Code Online (Sandbox Code Playgroud)
如何更正我的正则表达式以确保上面的第一个示例也有效,我尝试将 $ 符号放在方括号中,但这不起作用。
| 归档时间: |
|
| 查看次数: |
23703 次 |
| 最近记录: |