A
A
Alexander Proshchenkov2018-04-15 11:50:54
Python
Alexander Proshchenkov, 2018-04-15 11:50:54

How to use regular expressions to select 2 or more words?

There is a regular expression - %\w+%
It is from the line Monday:\n1.%Geography Math%(8:30-9:15)
Doesn't select anything, how can I make it select all of them regardless of the number of words inside %%?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2018-04-15
@Keltor

In [13]: list(re.findall('%(\w+ *\w+)%', '\n1.%География  Математика%(8:30-9:15)'))
Out[13]: ['География  Математика']

In [14]: list(re.findall('%(\w+ *\w+)%', '\n1.%ГеографияМатематика%(8:30-9:15)'))
Out[14]: ['ГеографияМатематика']

In [15]: list(re.findall('%(.+)%', '\n1.%ГеографияМатематика%(8:30-9:15)'))
Out[15]: ['ГеографияМатематика']

In [16]: list(re.findall('%(.+)%', '\n1.%География   Математика%(8:30-9:15)'))
Out[16]: ['География   Математика']

S
Saboteur, 2018-04-15
@saboteur_kiev

\w may not work with the Russian alphabet.
But try:
(?<=%)[^%]+(?=%)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question