正規表現に頭を悩ませています。
これまでのところ、私のパターンは次のようになっています (Python Verbose フレーバー正規表現)
(?P<text>
[a-zA-Z0-9]+ # can start with "core char"
[a-zA-Z0-9\ \-]* # can have a "core char" or space|dash within it
[a-zA-Z0-9]+ # must end with a "core character"
)
これを変更したいので、その中間セクション内で、スペースまたはダッシュの繰り返しがあると一致しません。テキスト内に複数のスペース/ダッシュを含めることは許容されます。
良い:
hello world
hello-world
h-ll-w-rld
悪い:
-hello-world
hello--world
h-ll--w-rld
hello world