I got a word 'myword' and i want to find all those words in a file, that contain 'myword' but not those who contain it at the beginning. Can you guys tell me how to do it by regular expressions in Python? I bet that i must use Word Boarder expression somehow.
\\b
stands for word boundary, and \\B
stands for "Not word boundary"
Following regular expression should work:
import re
matches = re.findall(r"\Bmyword", file_contents)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.