RegEx Workout 005 - Word identification

Welcome to another challenge in which we will use regex101.com to find patterns in text. If this is your first exercise, please check the first edition - you will find instructions there.

Task 1:

“The catastrophic novel entitled”“The Enigmatic Catalyst” features Osmund Blackcat and a talking cat"

Find the word “cat” in the following sentence. Skip the phrases that contain such a component.

Perform reverse operations: find words with a “cat” component, but omitting the standalone “cat”.

Task 2

“R offers color and colour parameters. This makes your chart colorful.The is no support for a person who is colorblind”

In the following sentence, find the names of the parameters, try not to use literal matching (color|colour)

Task 3

R includes corrr and corrplot libraries. Both support the study of corelations”

In the following sentence, mark the names of libraries that are characterized by multiple occurrences of the letter r.

Good luck. Answer will be publish on 18.06.2023

1 Like
Task1

\bcat\b

\w+cat|cat\w+|\w+cat\w+

Task2

co\w+(?=.*par)

Task3

\w*r{2}\w*

1 Like

Hi @KrzysztofNowak,

Thanks for the workout

Task 1:

Task 2:

Task 3:

Thanks for the workout . :slight_smile:
Keith

1 Like

Hello,
Please find my solution below:

Task 1

\bcat\b

\b(?!cat\b)\wcat\w\b

Task 2

\w*colou?r\b

Task 3

\w*r{2}.+?\b

Alex

1 Like

@KrzysztofNowak,

The tricky bit here was in Tasks 2 and 3 when ensuring to capture strings potentially separated by AND or OR and looking for the keywords library or libraries and parameter and parameters rather than literals. Those could be extended with commas to capture lists of 3 or more. I didn’t go back and remove the delimiters.

Here is my solution:

Task 1-a: / \bcat\b /g

Task 1-b:
/[[:<:]]cat[[:>:]]/g

Task 2: (\w+\W+(?>AND|OR)\W+\w+)|(\w+) param

Task 3:(\w+r{2}\W+(?>AND|OR)\W+\w+)|(\w+r{2}) lib

1 Like

Dears, big thanks for participation.

Please see my solutions.

Task 1

I used the word boundary operators here. The word must begin and end in a certain way. In addition, it uses here exact matching

Task 2
In this case, I start by establishing that the operators are not case-sensitive. I then state that both before and after the “cat” component there must be letters - any number

Task 3
Again, I specify that the case does not matter. Then I determine that we are dealing with a closed from the right word “color” with an optional (?) letter “u” in the middle.

Task 4

In this assignment, I return to the concept of word boundaries. It must start with the component “for”, but the letter “r” must occur at least 2 times. After that, there are any number of letters

1 Like

@borydobon , very good solutions. I like that you found case sensitivity function in interface

1 Like

Hi @Keith , very good solutions. You can combine class of characters, boundaries and lookbehind/ahead in one sentence, very nice!

Hi @alex-badiu , very good answers. I like combination of boundaries and negation in one solution!

Hi @HufferD , thank you for answers. I found it very interesting to create some kind of challange for solutions by adding components that reveals potential problems with expressions. I think it will be interesting to explore unit testing functionality of regex101.com
image

1 Like