FAQ: Introduction to Regular Expressions - Ranges

This community-built FAQ covers the “Ranges” exercise from the lesson “Introduction to Regular Expressions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Practical Data Cleaning

FAQs on the exercise Ranges

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Is the range in alphabetic order? Like if I had [a-d] You could enter “c” and it would work, but if you put “z” it wouldn’t? I would also assume that it would be very similar with numbers

Yes that’s the correct interpretation for using a range in a character class for regular expressions :wink:, a single lowercase later from a to d inclusive (a, b, c, d). Python’s guide to this is at the following-
https://docs.python.org/3/howto/regex.html#regex-howto

But the same expressions are covered in many places (sometimes in a nicer way if you’re trying to get it sorted quickly).

@tgrtim Oops! Silly me for not reading the title hahah. :sweat_smile: should be more awake when answering.

1 Like

I’m sharing this, hope it would be helpful.

[a-zAD61-48] will match either a-z or A or D or 6 or 1-4 or 8 of one char long (case sensitive).

eg.
matches a
matches d
matches z
matches A
matches D
NOT matches B
matches 6
matches 1
matches 4
matches 3
NOT matches 5
matches 8

I don’t understand how to solve the problem using ranges when I can only use 1 range set. [a-c][o-l] doesn’t match anything in the test strings. The interpreter only allows me to use 1 range .

What’s the intended solution here? What does this have to do with ranges?

This one is a bit annoying. No idea if its the intended solution or not, but I used
..[bgk]
It feels like this should be done with several ranges but as others have said the interpreter only allows one. If anyone else has another way I’d love to hear it

1 Like

I agree, frustrating indeed. In case anyone is struggling, the solution I got is [b-g][k-v][b-k]

I agree also - found the intention here less than clear - wasn’t expecting to use a multiple range approach

Each set (anything inside a pair of square brackets) will only match one character.

All the strings in the exercise are 3 characters in length, therefore, you need to use 3 sets.

A couple of previous posts have included incorrect or imprecise answers:

  • [a-c][o-l] – the second set doesn’t make sense. The range needs to be in alphabetical order, i.e. [l-o]
  • [b-g][k-v][b-k] – the first two sets are imprecise. Their ranges can be narrower, i.e [c-e][l-u]

Thank you for the reply - got it.

1 Like