Video Coming Soon...

Created by Zed A. Shaw Updated 2026-11-26 20:48:52
 

57: grep

WARNING: This is from the Go course but I'm rewriting the code and the description to fit C. If you want to attempt it go ahead. The challenge is the same, just no examples yet.

The grep command is an extremely useful tool. It searches through files--even recursively--looking for patterns of text. These patterns use something called a "regular expression", or "regex" for short. A regex uses simple characters to create a matching pattern that can search for things like, "all numbers starting with 0 through 9 before a lowercase letter."

Here's a quick regex crash course:

  • . -- means "any 1 character"
  • * -- means "zero or more of the previous"
  • + -- means "one or more of the previous"
  • [a-z] -- means "any character in the set of letters a-z." You can put any range here so [0-9] is numbers and [0-9a-z] is both.
  • \\ -- means "ignore the next character, it's not regex." So \. means, "ignore . it's not regex."

After that you can put any text you want and those letters get matched exactly. Here's some regex to try on your own code:

  • func [A-Z][a-zA-Z]* -- Find all exported functions. Read this as, "func followed by any capital letter then any number of lower or upper case letters."
  • [a-zA-Z]+ := -- Find all assignments. Read this as "any sequence of characters followed by a space and :=."
  • fmt\. -- Every line that uses fmt.
Previous Lesson Next Lesson

Register for From Impostor to Programmer

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.