Python 正则表达式:删除';那是一根绳子的?

Python 正则表达式:删除';那是一根绳子的?,python,regex,Python,Regex,字符串输入:Python的编程:非常容易学习 预期输出:Python编程:非常容易学习 以下是迄今为止我所拥有的不起作用的东西: import re mystr = "Python's Programming: is very easy to learn" reg = r'\w+' print(re.findall(reg, mystr)) 如何将的从python的中删除?这里有两个选项。第一个使用regex,第二个使用stringreplace方法 import re m

字符串输入:
Python的编程:非常容易学习

预期输出:
Python编程:非常容易学习

以下是迄今为止我所拥有的不起作用的东西:

import re
mystr = "Python's Programming: is very easy to learn"
reg = r'\w+'
print(re.findall(reg, mystr))

如何将
python的
中删除?

这里有两个选项。第一个使用regex,第二个使用string
replace
方法

import re
mystr = "Python's Programming: is very easy to learn"
reg = r"'s"
print(re.sub(reg, '', mystr))
   # prints: Python Programming: is very easy to learn
print(mystr.replace("'s",''))
   # prints: Python Programming: is very easy to learn

提取一个或多个字母数字字符的所有匹配项

使用

说明

--------------------------------------------------------------------------------
  \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
:

重新导入
mystr=“Python的编程:非常容易学习”
打印(re.sub(r“\b's\b”,'',mystr))

在不检查单词边界的情况下替换
会产生副作用。试着用
“这么棒的语言”
字符串。我真的不确定你说的是真的。在字符串上没有单词边界的情况下似乎可以正常工作。除非你的意思是
mystr=“‘这么棒的语言’”
。但这似乎极不可能消除这个词的界限。我认为他们在这种情况下是没有必要的。我也不想“复制”你的答案。我只是看到了对我的回答的评论,并对其进行了处理。没有看过你的答案。(从一个删除的答案中)看,这也回答了你的问题吗?与当前问题无关。
--------------------------------------------------------------------------------
  \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