![](/img/trans.png)
[英]python find all matches of multiple strings in a given string using regex?
[英]How to find all the exact matches in a given string using python Regex
我試圖從我的字符串中獲取所有 3 個字符的單詞,但只得到第一次出現
import re
a="AAA BBBBBBBBBB CCCCCCC DDD FFF"
print(re.findall('(^[A-Z]{3})',a))
實際 output:
['AAA']
預期的 Output 是:
['AAA','DDD','FFF']
^[AZ]{3}
將僅匹配字符串開頭的 3 個字符。
嘗試re.findall(r'\b[AZ]{3}\b', a)
它將適當地匹配單詞邊界。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.