Learning about regular expressions

Hi there, I am just getting started in this course and learning about deep learning. There are many links to video tutorials and posts about regular expressions in the Resources of Lesson 1. Should I invest a good amount of time learning about regular expressions now, or can it wait? Is the usage of regular expressions common in deep learning? I am trying to make the best use of my time and not get too into the weeds just yet.


1 Like

short answer, it can wait :slight_smile:

1 Like

Regular expressions are just a tool in certain tasks. You don’t need to invest much time on that.The best way to learn fast is by practice. Whenever you need to find a certain pattern in text try to do it using a regex and there is a good website https://regex101.com/ that can guide you and help you debug and understand each regex you type :wink:


I had this same question in my head about two weeks ago. It definitely can wait, but it’s not as hard as it looks.

There is a fantastic interactive tutorial at regexone.com. It will walk you through what everything means and give you problems to solve (that reflect what your regex pattern is matching in real time). Maybe takes an hour to an hour and a half. Hope that gives you more info to make a decision

1 Like

On a separate note, I think everyone comes into this class from different backgrounds. Many of us haven’t had exposure to the large number of technologies that, while not essential, are pretty important for deep learning. My personal list includes…

  • Git/Github
  • Numpy
  • Pandas
  • MatPlotLib
  • Jupyter Notebook
  • Regular Expressions
  • A remote editor like vim/nano/sublime

I think it would be great to have a thread or wiki with the best resources and tutorials for these mini-topics, just like we do for the recommended python resources. It would help people who are new to a lot more than AI to not get overwhelmed knowing there’s a neat list they can bite off one chunk at a time.

Finally it should include a warning that these are not in any way prerequisites that should take precedence over the lessons/code, but instead are meant to be tackled gradually based on what your most pressing AI needs are.

Let me know if this already exists somewhere and if not let’s build it!

1 Like

I am definitely late in replying here but thank you all for the feedback! Very good input to help me prioritize my learning time.

Hi. Im trying to write a regex for a filename of type “word-word-digits.jpg”.
My regex - ^\w+-\w+-\d+.(jpg|jpeg)$ . I checked it on https://regex101.com and it shows its a match with my string provided. But when i use it in the notebook i get an error " Failed to find “re.compile” " . Could someone help me with this. Thanks!

I try to prefer functions/lambdas over regular expression; according to my experience they’re simpler to maintain.

So if you already know RegExp, use them, otherwise use functions and focus on more interesting topics. As far as I remember I’ve never use regexp in any fast.ai notebook that I made.

NOTE: It’s fun to notice that from_re actually wraps from_func :wink:

    def label_from_re(self, pat:str, full_path:bool=False, label_cls:Callable=None, **kwargs)->'LabelList':
        "Apply the re in `pat` to determine the label of every filename.  If `full_path`, search in the full name."
        pat = re.compile(pat)
        def _inner(o):
            s = str((os.path.join(self.path,o) if full_path else o).as_posix())
            res = pat.search(s)
            assert res,f'Failed to find "{pat}" in "{s}"'
            return res.group(1)
        return self.label_from_func(_inner, label_cls=label_cls, **kwargs)

Its very simple, if you simply learn the syntax of writing regular expressions and how to do it in python, you’ll be all set. Its not that hard at all. regular expressions are just tools used for looking for patterns in text. follow this simple chart apart from basic definitions and you’ll understand everything.1944b14175b0136b578287c0169a5c69