edyvedy13
edyvedy13

Reputation: 2296

Getting numbers before and after strings using regex

I would like to get the numbers in pandas data frame before and after certain keywords such as word, words, page, pages

jobtitle
english to spanish translations and voice over recording of four short video scripts (1100 words total)
south american spanish - 5 min video 900 words translation & voice over
translate manufacturing training video script from english to spanish (word document)
translating 100 pages to spanish
translate 1500 word document from english to spanish
translate 2225 word document from english to spanish
translate page 103

I tried something like: "(?:([0-9]?[0-9])[a-zA-Z ]{0,20}(?:word|words))" but couldn't get them right.

Upvotes: 0

Views: 42

Answers (1)

The fourth bird
The fourth bird

Reputation: 163287

You could use an alternation | to match either page or word followed by an optional s

To match 0 or more whitespace chars except newlines, you could use [^\S\r\n]*

\b(\d+)[^\S\r\n]*(?:page|word)s?

Regex demo

Upvotes: 1

Related Questions