I have been trying to create a regex that will match on a string of strings with the following format: "static.string static.mod static.bin". I basically want to enforce the string.string format. My current implementation only gets the first string static.string. this is my RE ^(\s*)([A-Za-z]+)(\.+)([A-Za-z]+)
. This only matches the first string, so how do I make it iterate and match any string that fits that format in a string of strings?
You may use
re.findall(r'(?<!\S)[A-Za-z]+\.[A-Za-z]+(?!\S)', text)
See the regex demo .
The regex matches:
(?<!\S)
- a location immediately preceded with a whitespace or start of string [A-Za-z]+
- 1+ ASCII letters \.
- a dot [A-Za-z]+
- 1+ ASCII letters (?!\S)
- a location immediately followed with a whitespace or end of string.
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.