brett
brett

Reputation: 55

Python regex and spaces?

If I have a piece of text, i.e.

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

and want to create a regular expression that matches (see inside <> below)

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

How do I solve that part in the <>?

Upvotes: 0

Views: 62

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 208465

The following regex will match 1 word or many words separated by a space:

\w+( \w+)*

Here a "word" is considered to consist of letters, digits, and underscores. If you only want to allow letters you could use [a-zA-Z]+( [a-zA-Z]+)*.

Upvotes: 2

Related Questions