Regular Expressions

Flashcard 4 of 10

In the following pattern we have to use \ a number of times to escape the / character that would typically signify the end of the pattern.

/https:\/\/.*?\/api\/(.*?)\/(.*?)/

Is there any way we can clean this up to remove the noise of the \ escape characters?

Ruby has an alternative regex constructor, %r{...} that allows us to write our pattern without needing to escape / characters. Using this constructor, our pattern can be cleaned up as follows:

%r{https://.*?/api/(.*?)/(.*?)}
Return to Flashcard Results