首页 > 解决方案 > 如何在mysql中匹配类似于like的python字符串

问题描述

a = "This is some text"
b = "This text"

我想比较 a 中的变量 b 并且即使文本包含两个以上的单词也应该返回 true

a = "This is another text here"
b = "This another here"

即使我在 a 中比较 b 应该在 python 中返回 true

条件True==b找到所有单词,顺序相同,在a.
在上面的例子中,单词必须是相同的顺序和大写/小写。

标签: pythonregex

解决方案


a = "This is some text"
b = "This text"

c = 0 
for i in b.split(): # check for each word in a
    if i in a: c = c + 1 # if found increases the count
c>=2 # true

或者

len([value for value in a.split() if value in a.split()]) >= 2

推荐阅读