From the course: Linux Foundation Certified System Administrator (LFCS) Cert Prep

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Analyze text using basic regular expressions

Analyze text using basic regular expressions

- [Instructor] In this lesson, we will explore regular expressions, also called regex for short. Now, in our previous commands we use simple search patterns, looking for some specific pieces of text, like password. But what if we need more complex search conditions? Imagine we have some application code scattered in hundreds of files, and we need to extract all the IP addresses that are used in this app. That would require more advanced search instructions, because an IP has a form like 203.102.3.5. But we can't just make a search pattern look for numbers with a period between them as this would also match numbers like 5.23, which are not IP addresses. Now in math, we can say something like X is an integer, and X is bigger than three, X is smaller than eight, and this would mean that X is either 4, 5, 6, or 7. Now regular expressions work in a similar way. We can specify some conditions, tie them all together, and our search pattern only matches what perfectly fits within those…

Contents