Skip to main content
Solved

Looking for only the numbers that come before a certain word

  • December 4, 2022
  • 2 replies
  • 48 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2938 replies
  • Best Answer
  • December 4, 2022

StringSearcher with regex should do this.


michiedem
Contributor
Forum|alt.badge.img+7
  • Author
  • Contributor
  • 52 replies
  • December 4, 2022

StringSearcher with regex should do this.

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