ALL LINUX
  • Linux 4 Network Engineers
  • Introduction
    • Untitled
  • LINUX - "HOW-TO-DO"
    • SYSADMIN
      • MONITORING
        • Stress Testing Linux
      • DEBIAN APT
      • DISK
        • Directory Share - NFS,CIFS
        • LOGICAL VOLUME MANAGEMENT (LVM)
        • FILE SYSTEMS
          • ZFS
      • FIND & DU
      • SECURITY
        • SSH Open Format
      • USERS
        • Accounts, Groups etc
        • Assess User Activity
    • SCRIPTING & TEXT EDIT
      • BASH SCRIPTING & PROJECTS
        • 1) How to Build a Bash Script
        • 2) Variables & Shell Expansions
        • 3) Processing Command Lines
        • 4) Requesting User Input
      • VIM Editor
        • Vim Tips
      • GREP, EGREP & REGEX
        • REGEX
        • REGEX2
        • NINJA-REGEX
      • SED and AWK
  • Containers
    • MULTIPASS
    • LXD LXC
    • KUBERNETES (K8's)
  • FOSS
    • CUMULUS LINUX
      • Fundamentals
        • Cumulus Linux Introduction
        • Cumulus Linux Architecture
        • Cumulus VX
        • Initial Setup
      • NCLU
  • Linux Prof Inst Cert [LPIC-1]
    • LPIC 1
      • CH1-Linux Command-Line Tools
        • Work on the Command Line
        • Streams, Pipes and Redirects
          • Text Streams Using Filters
        • Search Text Files - Regular Expressions
        • Basic File Editing
      • CH2-Managing software and Processes
      • Ch3-Configuring Hardware
      • Ch4-Managing Files
      • Ch5-Booting, Initialising and Virtualising Linux
Powered by GitBook
On this page
  • Resources
  • Character Sets [ ]
  • Metacharacters and Escaping
  • Special Characters

Was this helpful?

  1. LINUX - "HOW-TO-DO"
  2. SCRIPTING & TEXT EDIT
  3. GREP, EGREP & REGEX

NINJA-REGEX

This is mainly for my understanding of Regex as well as its functions and uses predominantly in Python3 as well as in its use in BASH shell scripts and UNIX grep, awk and sed

PreviousREGEX2NextSED and AWK

Last updated 4 years ago

Was this helpful?

Resources

Character Sets [ ]

Any first character from [a-z]inja will match as below. However any capitals are ignored

The range a-z can be written as [a-z]inja. Dont have to include all the way to 'z' but a-f or s-w, or whatever we require. [a-zA-Z0-9]inja will match the first charachter from a-z or A-Z or 0-9

Telephone number: 11 numbers [0-9]{11} - This will match 11 numbers exactly Between 5-8 numbers [0-9]{5,8}. If you want AT LEAST 5 numbers [0-9]{5,} --we just leave the comma with nothing after and close the braces

Metacharacters and Escaping

Special Characters

There are 12 characters with special meanings and are called "METACHARACTERS". These metacharacters add more functionality and meaning when matching strings. They are:

METACHARACTERS

DESCRIPTION

EXAMPLE

\ Backslash

Signals a special sequence (can also be used to escape special characters)

\d

^ Caret

Starts with

^hello

$ Dollar Sign

Ends with

world$

. Period

Any character (except newline character)

h..o

| Pipe

Either or

stay | go

? Question Mark

Preceding character is optional

colou?r matches color and colour

* Asterix

Zero or more occurrences

aix*

+ Plus

One or more occurrences

aix+

( ) Parenthesis

Capture and Group

[ ] Square Bracket

A set of characters

[a-m]

{ } Curly brace

Exactly the specified number of characters

{2,4}

Regular Expressions - Net Ninja
Regular Expressions 101
Tutorial - regular-expressions.info/tutorial.html
https://www.rexegg.com/