Exercise 1: Capture the Class Names
Practice extracting data contained within class tags using Ruby's regular expressions. Understand how to work with text input and apply regex patterns to isolate specific content between tags, reinforcing your skills in advanced Ruby topics.
We'll cover the following...
We'll cover the following...
Problem
You’re given an input text that contains some data (alphabetical characters only). This data appears between two different types of tags. It appears between either the class tags or the object tags as shown:
-
<class>Something</class> -
<object>SomeOtherThing</object>
Your task is to use a regular expression to extract the data enclosed within the class tags.
Example
Consider the input below:
<class>Hash</class> <object>true</object> <object>nil</object> <class>TrueClass</class>
The output should be:
[["Hash"],["TrueClass"]]