python - 正则表达式:从字符串中删除's?
问题描述
字符串输入:Python's Programming: is very easy to learn
预期输出:Python Programming: is very easy to learn
这是我到目前为止没有工作的内容:
import re
mystr = "Python's Programming: is very easy to learn"
reg = r'\w+'
print(re.findall(reg, mystr))
如何删除's
from python's
?
解决方案
您提取一个或多个字母数字字符的所有匹配项。
利用
\b's\b
见证明。
说明:
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
's '\'s'
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
蟒蛇代码:
import re
mystr = "Python's Programming: is very easy to learn"
print(re.sub(r"\b's\b", '', mystr))
推荐阅读
- azure - 在公共 IP 访问上自动启动 Azure 虚拟机很热门?
- google-apps-script - Automatically email deleted rows using googlescript
- rxjs - ionic 4中的订阅类型变量声明问题
- upload - UploadCollection: Non-working drag & drop functionality by using setUploadEnabled
- c++ - 如何使具有 QPoint 指针成员的类入队和出队?
- java - 延迟初始化页面对象元素
- javascript - Iterating array-like objects using forEach, [].forEach.call(...) or Array.prototype.slice.call(...).forEach?
- javascript - How can I create an array of comma separated arrays using java
- eclipse-rcptt - “消息框信息不存在”错误使用 get-last-message-box
- c# - Unity:Firebase 实时数据库 - OrderByChild 不起作用