【发布时间】:2022-03-03 15:47:25
【问题描述】:
我有这些输入:
s1 = 'I am using c++ programming'.
s2 = = 'I am usingc++ programming'.
我想检查 s1 或 s2 是否包含确切的单词 c++。
在 s1 和 s2 上运行这个正则表达式,它没有给出任何输出:
x=s1 #x=s2
if re.search(r'\bc\+\+\b', x):
print(x)
预期结果:在 s1 中检测到 c++
【问题讨论】:
-
re.search(r'\bc\+\+\B', the_string) -
你也可以
if 'c++' in the_string.split() -
一些关于欺骗链接的相关答案,但问题的性质似乎不同
-
@anubhava 如果你的意思是从一个字符串中多次出现,那么How can I find all matches to a regular expression in Python?
-
这能回答你的问题吗? Regex to match a word with + (plus) signs