我无法将头绕在正则表达式上。
到目前为止,我的模式看起来像这样(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