0

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.

3
  • 2
    Why so complicated? It seems for your example you could simply use (\d+)\s*word[s]?, see regex101.com/r/yNuOmJ/1 Commented May 4, 2020 at 18:54
  • Then you use another one for page, and another one where the number comes after the word. Why does it have to be a single regex to cover all the cases? Commented May 4, 2020 at 18:56
  • No I just show that as an example, I also need one for regex Commented May 4, 2020 at 19:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.