简体   繁体   English

在Python中等效的Javascript“匹配”

[英]Equivalent of Javascript “match” in python

I have a method for extracting all the "words" from a string in javascript: 我有一个方法从javascript中的字符串中提取所有“单词”:

mystring.toLowerCase().match(/[a-z]+/g);

I'd like to convert that same logic (create an array of "words" from my string), but in python. 我想转换相同的逻辑(从我的字符串创建一个“单词”数组),但在python中。 How can I achieve that? 我怎样才能做到这一点?

Use findall() , which is similar to String.prototype.match() . 使用findall() ,它类似于String.prototype.match()

import re
regex = r"[a-z]+"
matches = re.findall(regex, strToScan)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM