Extended Regular Expressions Characters

 regular_express.txt

 
+ : Repeat the previous RE character of one or more.
Example : Search for "god" "good" "goood"... etc. strings. 
egrep -n 'go+d' regular_express.txt
 
 
? : Zero or one before the RE character.
Example: Search for the two strings "gd" and "god".
egrep -n 'go?d' --color=auto regular_express.txt 


| : Find out several strings by OR.
Example: Search for the two strings "gd" or "good".
egrep -n 'gd|good' --color=auto regular_express.txt


() :  Find group string.
Example: Search for the two strings "glad" or "good", because "g" and "d" are duplicates, so I can list "la" and "oo" in () and separate them with | 
egrep -n 'g(la|oo)d' --color=auto regular_express.txt


()+ :  Identification of multiple repeated groups.
Example: I'm looking for a string that starts with "A" and ends with "C", and there is more than one "xyz" string in the middle.
echo 'AxyzxyzxyzC' | egrep 'A(xyz)+C' --color=auto

 

Comments

Popular posts from this blog

BdsDex: failed to load Boot0001 "UEFI BHYVE SATA DISK BHYVE-OABE-20A5-E582" from PciRoot(0x0)/Pci (0x2, 0x0)/Stat(0x0,0xFFFF,0x0) : Not Found

How To Install Nginx, MySQL and PHP (FEMP) Stack on FreeBSD 13.0

Install samba on FreeBSD(on VMware Workstation) to share files with Window.