Start a new topic

RegEx to return number only from middle of text field

We have incoming data in a text field that looks like these examples:


HIKE: Hike name here - 3 Hikers

HIKE: Other hike name here - 12 Hikers

HIKE: 10th Anniversary Hike name - 1 Hikers


I would like to create a dictionary that pulls out the number of hikers so that it can be put in an RE attribute that takes only numbers. So, in the cases above:


3

12

1


A few notes:

  • The names of the hikes will vary in their length.
  • The number of hikers always follows a hyphen and then a space.
  • The word "Hikers" always follows the number of hikers (after a space), even for a single hiker.
  • The number of hikers may be single or double digit.
  • The names of hikes many even contain numbers themselves (like the 10th anniversary example) BUT I only want the number that appears after the hyphen and space and before "Hikers"


The closest I've gotten is to create a RegEx to return everything after the hyphen and space. So:

Replacement Value: --BLANK--

Values to Match on: .*(?<=- )


Which returns:

3 Hikers

12 Hikers

1 Hikers


But I need to have only a numerical value in this field. How do I also get rid of " Hikers"? I'm sure I need to take a different approach.


Add a second line to your dictionary to remove " hikers"

Oh my goodness. That did it. I was so close!

I am very new to RegEx but this does feel like a bit of a face palm moment.

Thank you, Barbara.

You're welcome!

Login or Signup to post a comment