Skip to main content
Solved

Looking for only the numbers that come before a certain word


michiedem
Contributor
Forum|alt.badge.img+7

I have a dataset with a messy 'comments' column. I want to extract numbers from these comments, but only when the come before a ceratin word. For instance, a comment could be:

 

on januari 21, 16 boats passed

or

21 boats passed on januari 12 2017

 

I only want the numbers when they come beofre the word 'boat'. Is there a way to do that?

Best answer by nielsgerrits

StringSearcher with regex should do this.

View original
Did this help you find an answer to your question?

2 replies

nielsgerrits
VIP
  • Best Answer
  • December 4, 2022

StringSearcher with regex should do this.


michiedem
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • December 4, 2022
nielsgerrits wrote:

StringSearcher with regex should do this.

Thanks. I was struggling with the regex, but found it: \\d+(?=\\ boats)


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings