Member-only story

100 Days of DevOps — Day 53-Introduction to Regular Expression — Part 1

Prashant Lakhera
4 min readApr 5, 2019

Welcome to Day 53 of 100 Days of DevOps, Focus for today is Introduction to Regular Expression

What is a Regular Expression?

It’s a pattern matching language

OR

Regular expressions are specially encoded text strings used as patterns for matching sets of strings

OR

Is a sequence of characters that define a search pattern

This is what Regular Expression looks like

\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
  • To break down this
* \d : Matches a digit 0-9
* {1,3}: Repeat the prior pattern 1-3 times
* . : is a wildcard, so we need to escape it

The above expression match any IP address

eg:

192.168.0.1
127.0.0.1

The concept we have just learned let’s try to use it with grep command

  • I have a file called myipaddress
# cat myipaddress192.168.0.1172.16.0.210.0.0.3
  • to grep ip address from this file
# grep -P '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' myipaddress192.168.0.1172.16.0.210.0.0.3

--

--

Prashant Lakhera
Prashant Lakhera

Written by Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

No responses yet