You can use this regex:
(?:[^-\w]|^)(?P<part1>[a-zA-Z]+)-(?P<part2>[a-zA-Z]+)(?:[^-\w]|$)
(?: # non capturing group
[^-\w]|^ # a non-hyphen or the beginning of the string
)
(?P<part1>
[a-zA-Z]+ # at least a letter
)-(?P<part2>
[a-zA-Z]+
)
(?:[^-\w]|$) # either a non-hyphen character or the end of the string
- Your first problem is that nothing prevents the
.
from eating up spaces.[a-zA-Z]
only select letters so it will avoid "jumping" from one word to another. - For the
pok-e-mon
case, you need to check that there isn't a hyphen right before or after your match.
See Demo here