如何匹配我已经预定义的字符串,然后将它们提取出来(如果它们存在于我要传递的段落中)。
PARAGRAPH:Paragraph are the building blocks of papers. Many student define paragraph in terms of length: a paragraph is a group of at least five sentences, a paragraph is half a page long, etc. In reality, though, the unity and coherence of ideas among sentences is what constitutes a paragraph
预定义的字符串:['paragraph','building blocks', 'length', 'page', 'students']
输出:
['paragraph', 'paragraph', 'paragraph', 'paragraph', 'paragraph', 'length', 'page', 'student' ]
代码:
match = []
string_doob = paragraph.lower()
for i in predefined_string:
if i in string_doob:
match.append(i)
print(match)
答案 0 :(得分:1)
使用预定义的字符串作为正则表达式(请参见模块// server, before popup is opened:
cache.put('cell_currently_being_edited', active_doc.getCursor().getElement().getParent());
// popup client calls server function like so:
google.script.run.withSuccessHandler(load_content).get_starting_content();
// server, where the above error occurs:
function get_starting_content() {
var cell_currently_being_edited = cache.get('cell_currently_being_edited');
return cell_currently_being_edited.getText();
}
)和re
编辑:不使用正则表达式:为每个字符串遍历您的段落,如果段落中的字符串为re.findall
,直到该字符串不在段落中
EDIT2:
replace