How use regex to select words that have a character in common

(Kurt) #1

I need to find through regex words that contain a character in common. For example:

Among the words below, I want to select only those that have underline:

car_red , car_blue, car

How to write a regex that does this: getthat takes all words that contain a character?

(Kurt) #2

I tried to use the regular expression ‘’…_… "

So, from the following sentence:
“car_red”:“limozine”,“car_blu”:“ferrari”

I should have 2 matchs. But only the first came: car_red

Why?

(Kurt) #3

Now I tried to use the regular expression ‘’(…_… )"

So, from the following sentence:
“car_red”:“limozine”,“car_blu”:“ferrari”

I should have 2 diffent matchs: car_red and car_blu . But, I have 2 same matchs : car_red and car_red

Why? I’m testing this on an external regex expression tester and it worked.

(Daniel Beckett) #4

@Gregorio_Rodrigues1

I’ve just tested the following expression:
/…_…/g

This seems to work when used with the Text > Find Matches action.

Match 1 returns car_red and Match 2 contains car_blu

(Joe Hatch) #5

Just be careful to test your RegEx, the one provided by Daniel will work for

car_red and car_blu but it’s limiting the characters to 3 digits either side.

Your original post says car_blue (which would only be matched as car_blu).

You can use

/(.+)_(.+)/g

which will match any number of characters, a literal underscore then another group of characters which will return car_blue.

Hope that helps.

3 Likes