What is a regular expression?

Question

We learn here that grep stands for “global regular expression print”. What is a regular expression?

Answer

A regular expression is a technique for encoding a string pattern. By sting pattern, I mean that you decide on a specific set of rules that any string matching your expression should satisfy. For instance, say I want all strings which contain “Codecademy” as a substring where the letters within “Codecademy” can be either capital or lower case. For example, “CODECADEMY” is fine as is “CodeCadEMY”. Regular expressions provide a compact way of encoding this logic into a sequence of characters.

Although the example I presented is easy to program into a reasonably small function, regular expressions provide a consistent interface for performing arbitrary string matches; many of which would require large, error-prone, functions. The particular sequence which encodes a regular expression is similar but not the same across all languages. Because of this, if you’re interested in experimenting with regular expressions, find the syntax and library specific to your language of choice. You can find this by searching something along the lines of “regular expressions in <MY FAVORITE LANGUAGE>.”

13 Likes

line 2 of the answer, there is a typo . "By String pattern

Hmmm…I typed each character by the letter and output was printed out. However, the question is still showing as incorrect?

1 Like

I’m having the same issue for instruction #2.

I had the same exact issue for question 2 and then I figured out they want “-Rl” not “R1”. The font used in the lessons makes the letter “l” completely identical to the number “1”. Hope this helps!

4 Likes

hi, did not help… I have tried -RI not working I tried -Rl too and it also does not work just as -RL and Ri also did not work… I cannot continue the lesson until I can make the assignment turn green … what to do to get this right???

Did you type exactly what the step instructs you to do?

-Rl should be -, followed by a capital R and a lowercase l.

2 Likes

I closed down and reopened and now it works, thanks!

1 Like