I want to return all the words which start and end with letters or numbers. They may contain at most one period . OR hypen -in the word.
So, ab.ab is valid but ab. is not valid.
import re
reg = r"[\d\w]+([-.][\d\w]+)?"
s = "sample text"
print(re.findall(reg, s))
It is not working because of the parenthesis. How can I apply the ? on combination of [-.][\d\w]+