Regular Expressions Matching Simple Patterns Selecting a certain line from a list based on a word in certain location

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

I have the following list:

1. Alon Cohen
2. Elad Yaron
3. Yaron Amrani
4. Yogev Yaron

I want to select the first name of the guys with the Yaron surname.

Since I don't care about what number it is I'll just put it as whatever digit it is and a matching dot and space after it from the beginning of the line, like this: ^[\d]+\.\s.

Now we'll have to match the space and the first name, since we can't tell whether it's capital or small letters we'll just match both: [a-zA-Z]+\s or [a-Z]+\s and can also be [\w]+\s.

Now we'll specify the required surname to get only the lines containing Yaron as a surname (at the end of the line): \sYaron$.

Putting this all together ^[\d]+\.\s[\w]+\sYaron$.

Live example: https://regex101.com/r/nW4fH8/1



Got any Regular Expressions Question?