Python正则表达式和空格?

时间:2013-05-09 18:13:59

标签: python regex

如果我有一段文字,即

title="gun control" href="/EBchecked/topic/683775/gun-control"

并希望创建匹配的正则表达式(请参阅下面的<>

title="<1 word or many words separated by a space>" href="/EBchecked/topic/\w*/\S*"

如何在<>中解决该部分?

1 个答案:

答案 0 :(得分:2)

以下正则表达式将匹配由空格分隔的1个单词或多个单词:

\w+( \w+)*

这里“单词”被认为由字母,数字和下划线组成。如果您只想允许使用[a-zA-Z]+( [a-zA-Z]+)*字母。