Exercise 1: Capture the Class Names
Write a regular expression to extract data from the given text.
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"]]
Try it yourself
Press + to interact
def extract_data(input_text)#Start your code herereturn resultend
to save progress
Quiz on Advanced Topics
Exercise 2: Using a Module
to save progress