SlideShare a Scribd company logo
1 of 10
String Processing with REGEX
Regular Expressions
• Regular Expression is a mean for defining text patterns.
It is vastly used in various implementation of automatic
computing tasks
• Regular expressions can be used when working with different
programming languages, such as Perl, AWK and TCL or with
some of the Linux power tools such as sed, grep, awk, expr
and VI
• There are two main types of regular expressions usage
– Matching
– Substitution
Note: Regular expression can be also referred as regexp or
REGEX
Regular Expressions
• REGEX are different from the shell’s meta-characters, even
though they make use of similar characters; They should
always be quoted in order to protect them from the shell.
Note: There are some variants and additions in the REGEX
syntaxes between the different commands; if something does
not work or if in doubt, consult the man pages of that
program.
Regular Expressions
• Below is a list of some of the common REGEX and their
values:
 . - match any single character.
 [list] – matches any single character in the list.
 [range] – matches any single character in the range.
 [^range] - matches any single character, not in list or range.
 * - matches previous character 0 or more times.
 {n} – matches previous character n times.
 {n,} – matches previous character at least n times.
 {n,m} – matches previous character between n and m times.
 ^ - matches regex at the start of the line Only.
 $ - matches regex at the end of the line Only.
  - quote. Cancels the meaning of a meta-character.
Regular Expressions
| - Logical OR
& - Logical AND
! - Logical NOT
• Regular Expression parsing is done simply be interpreting
each char, from left to right.
When matching, each text line will be tested for a match
against the Regular Expression every time a new character is
being parsed
• Each character matches itself, unless it is a meta-character.
Regular Expressions
• Some examples for REGEX matching:
# egrep '^u' /etc/passwd
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
# egrep '^[^a-v]' /etc/passwd
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
sed
• ‘sed’ is a stream editor, it parses and edit text according to a
predefined set of commands
• Syntax:
 sed [options] ‘command(s)’ [file]
• Options:
 -i modify the file data
 -e adds support for multiple commands
 -n do not output lines by default
By default, the “sed” command does not change the contents of
files; the safer way to make the changes is to redirect the new
output, after “sed” has done its trick into a new file.
sed
• ‘sed’ uses Regular Expression commands to do both matching
and text manipulation
• Regular Expression commands can be pretty confusing, as the
command declaration can be on both sides of the regexp
declaration
• Syntax:
 [command]/regexp/[command][arguments]
– ‘/regexp/p’ Print matched text (to be used with ‘-n’)
– ‘/regexp/d’ Delete matched text
– ‘s/regexp/string/[g]’ Substitute matched text with string
sed
• ‘sed’ is one of the more complex Linux power tools.
For most advanced usages, it has two main competitors: Perl
and ‘awk’. Both are fully featured programming languages.
• Example
# cat file
one two three
four five six
# sed 's/([a-z]*) ([a-z]*) ([a-z]*)/1 SECRET 3/g' file
sed
• ‘sed’ is one of the more complex Linux power tools.
For most advanced usages, it has two main competitors: Perl
and ‘awk’. Both are fully featured programming languages.
• Example
# cat file
one two three
four five six
# sed 's/([a-z]*) ([a-z]*) ([a-z]*)/1 SECRET 3/g' file

More Related Content

Viewers also liked

Hcad competencies booklet (2) (1)
Hcad competencies booklet (2) (1)Hcad competencies booklet (2) (1)
Hcad competencies booklet (2) (1)Ngonde
 
Hoopsfix All Star Classic 2014 Programme
Hoopsfix All Star Classic 2014 ProgrammeHoopsfix All Star Classic 2014 Programme
Hoopsfix All Star Classic 2014 ProgrammeHoopsfix
 
Help me Obi-Social Kenobi: Social is my only hope
Help me Obi-Social Kenobi: Social is my only hopeHelp me Obi-Social Kenobi: Social is my only hope
Help me Obi-Social Kenobi: Social is my only hopeBloomfire
 
CyberScope - 2015 Market Review
CyberScope - 2015 Market ReviewCyberScope - 2015 Market Review
CyberScope - 2015 Market Reviewresultsig
 
Geek Sync I Dealing with Bad Roommates - SQL Server Resource Governor
Geek Sync I Dealing with Bad Roommates - SQL Server Resource GovernorGeek Sync I Dealing with Bad Roommates - SQL Server Resource Governor
Geek Sync I Dealing with Bad Roommates - SQL Server Resource GovernorIDERA Software
 
Who, What, Where and How: Why You Want to Know
 Who, What, Where and How: Why You Want to Know Who, What, Where and How: Why You Want to Know
Who, What, Where and How: Why You Want to KnowEric Kavanagh
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usageShay Cohen
 
5 Winning Strategies - Social Ecommerce Ebook
5 Winning Strategies - Social Ecommerce Ebook5 Winning Strategies - Social Ecommerce Ebook
5 Winning Strategies - Social Ecommerce EbookMelih ÖZCANLI
 
The Art of Visibility: Enabling Multi-Platform Management
The Art of Visibility: Enabling Multi-Platform ManagementThe Art of Visibility: Enabling Multi-Platform Management
The Art of Visibility: Enabling Multi-Platform ManagementEric Kavanagh
 
Geek Sync I CSI for SQL: Learn to be a SQL Sleuth
Geek Sync I CSI for SQL: Learn to be a SQL SleuthGeek Sync I CSI for SQL: Learn to be a SQL Sleuth
Geek Sync I CSI for SQL: Learn to be a SQL SleuthIDERA Software
 
Geek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual DatabaseGeek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual DatabaseIDERA Software
 
About the authors
About the authorsAbout the authors
About the authorsbutest
 
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...Dealmaker Media
 
Dit Was 2008 Sofie Van Hoof
Dit Was 2008   Sofie Van HoofDit Was 2008   Sofie Van Hoof
Dit Was 2008 Sofie Van Hoofsvanhoof
 

Viewers also liked (15)

Hcad competencies booklet (2) (1)
Hcad competencies booklet (2) (1)Hcad competencies booklet (2) (1)
Hcad competencies booklet (2) (1)
 
Hoopsfix All Star Classic 2014 Programme
Hoopsfix All Star Classic 2014 ProgrammeHoopsfix All Star Classic 2014 Programme
Hoopsfix All Star Classic 2014 Programme
 
Help me Obi-Social Kenobi: Social is my only hope
Help me Obi-Social Kenobi: Social is my only hopeHelp me Obi-Social Kenobi: Social is my only hope
Help me Obi-Social Kenobi: Social is my only hope
 
CyberScope - 2015 Market Review
CyberScope - 2015 Market ReviewCyberScope - 2015 Market Review
CyberScope - 2015 Market Review
 
Geek Sync I Dealing with Bad Roommates - SQL Server Resource Governor
Geek Sync I Dealing with Bad Roommates - SQL Server Resource GovernorGeek Sync I Dealing with Bad Roommates - SQL Server Resource Governor
Geek Sync I Dealing with Bad Roommates - SQL Server Resource Governor
 
Who, What, Where and How: Why You Want to Know
 Who, What, Where and How: Why You Want to Know Who, What, Where and How: Why You Want to Know
Who, What, Where and How: Why You Want to Know
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usage
 
5 Winning Strategies - Social Ecommerce Ebook
5 Winning Strategies - Social Ecommerce Ebook5 Winning Strategies - Social Ecommerce Ebook
5 Winning Strategies - Social Ecommerce Ebook
 
The Tux 3 Linux Filesystem
The Tux 3 Linux FilesystemThe Tux 3 Linux Filesystem
The Tux 3 Linux Filesystem
 
The Art of Visibility: Enabling Multi-Platform Management
The Art of Visibility: Enabling Multi-Platform ManagementThe Art of Visibility: Enabling Multi-Platform Management
The Art of Visibility: Enabling Multi-Platform Management
 
Geek Sync I CSI for SQL: Learn to be a SQL Sleuth
Geek Sync I CSI for SQL: Learn to be a SQL SleuthGeek Sync I CSI for SQL: Learn to be a SQL Sleuth
Geek Sync I CSI for SQL: Learn to be a SQL Sleuth
 
Geek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual DatabaseGeek Sync | Avoid Corruption Nightmares within your Virtual Database
Geek Sync | Avoid Corruption Nightmares within your Virtual Database
 
About the authors
About the authorsAbout the authors
About the authors
 
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...
Searching for Users: SEO as an Engine for Customer Acquisition (Stephan Spenc...
 
Dit Was 2008 Sofie Van Hoof
Dit Was 2008   Sofie Van HoofDit Was 2008   Sofie Van Hoof
Dit Was 2008 Sofie Van Hoof
 

Similar to 09 string processing_with_regex copy

Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHPAndrew Kandels
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expressionGagan019
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
4 lexical and syntax
4 lexical and syntax4 lexical and syntax
4 lexical and syntaxMunawar Ahmed
 
CiNPA Security SIG - Regex Presentation
CiNPA Security SIG - Regex PresentationCiNPA Security SIG - Regex Presentation
CiNPA Security SIG - Regex PresentationCiNPA Security SIG
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionskeeyre
 
Assembly language
Assembly languageAssembly language
Assembly languagePiyush Jain
 
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptxintroductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptxmayilcebrayilov15
 
Alexey Golub - Writing parsers in c# | 3Shape Meetup
Alexey Golub - Writing parsers in c# | 3Shape MeetupAlexey Golub - Writing parsers in c# | 3Shape Meetup
Alexey Golub - Writing parsers in c# | 3Shape MeetupOleksii Holub
 
How does intellisense work?
How does intellisense work?How does intellisense work?
How does intellisense work?Adam Friedman
 

Similar to 09 string processing_with_regex copy (20)

Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
 
RegEx Parsing
RegEx ParsingRegEx Parsing
RegEx Parsing
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Lecture_4.pdf
Lecture_4.pdfLecture_4.pdf
Lecture_4.pdf
 
PostgreSQL - Case Study
PostgreSQL - Case StudyPostgreSQL - Case Study
PostgreSQL - Case Study
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
4 lexical and syntax
4 lexical and syntax4 lexical and syntax
4 lexical and syntax
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
 
1 4 sp
1 4 sp1 4 sp
1 4 sp
 
CiNPA Security SIG - Regex Presentation
CiNPA Security SIG - Regex PresentationCiNPA Security SIG - Regex Presentation
CiNPA Security SIG - Regex Presentation
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Assembly language
Assembly languageAssembly language
Assembly language
 
PPT 19.pptx
PPT 19.pptxPPT 19.pptx
PPT 19.pptx
 
Intro to Perl
Intro to PerlIntro to Perl
Intro to Perl
 
Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptxintroductiontoperl-springpeople-150605065831-lva1-app6891.pptx
introductiontoperl-springpeople-150605065831-lva1-app6891.pptx
 
Alexey Golub - Writing parsers in c# | 3Shape Meetup
Alexey Golub - Writing parsers in c# | 3Shape MeetupAlexey Golub - Writing parsers in c# | 3Shape Meetup
Alexey Golub - Writing parsers in c# | 3Shape Meetup
 
How does intellisense work?
How does intellisense work?How does intellisense work?
How does intellisense work?
 

More from Shay Cohen

Linux Performance Tunning Memory
Linux Performance Tunning MemoryLinux Performance Tunning Memory
Linux Performance Tunning MemoryShay Cohen
 
Linux Performance Tunning Kernel
Linux Performance Tunning KernelLinux Performance Tunning Kernel
Linux Performance Tunning KernelShay Cohen
 
Linux Performance Tunning introduction
Linux Performance Tunning introductionLinux Performance Tunning introduction
Linux Performance Tunning introductionShay Cohen
 
chroot and SELinux
chroot and SELinuxchroot and SELinux
chroot and SELinuxShay Cohen
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
 
Infra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationInfra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationShay Cohen
 
14 network tools
14 network tools14 network tools
14 network toolsShay Cohen
 
13 process management
13 process management13 process management
13 process managementShay Cohen
 
12 linux archiving tools
12 linux archiving tools12 linux archiving tools
12 linux archiving toolsShay Cohen
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copyShay Cohen
 
10 finding files
10 finding files10 finding files
10 finding filesShay Cohen
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_toolsShay Cohen
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editorShay Cohen
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissionsShay Cohen
 
05 standard io_and_pipes
05 standard io_and_pipes05 standard io_and_pipes
05 standard io_and_pipesShay Cohen
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bashShay Cohen
 
03 browsing the filesystem
03 browsing the filesystem03 browsing the filesystem
03 browsing the filesystemShay Cohen
 
01 linux history overview
01 linux history overview01 linux history overview
01 linux history overviewShay Cohen
 

More from Shay Cohen (18)

Linux Performance Tunning Memory
Linux Performance Tunning MemoryLinux Performance Tunning Memory
Linux Performance Tunning Memory
 
Linux Performance Tunning Kernel
Linux Performance Tunning KernelLinux Performance Tunning Kernel
Linux Performance Tunning Kernel
 
Linux Performance Tunning introduction
Linux Performance Tunning introductionLinux Performance Tunning introduction
Linux Performance Tunning introduction
 
chroot and SELinux
chroot and SELinuxchroot and SELinux
chroot and SELinux
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Infra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationInfra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automation
 
14 network tools
14 network tools14 network tools
14 network tools
 
13 process management
13 process management13 process management
13 process management
 
12 linux archiving tools
12 linux archiving tools12 linux archiving tools
12 linux archiving tools
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copy
 
10 finding files
10 finding files10 finding files
10 finding files
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_tools
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editor
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissions
 
05 standard io_and_pipes
05 standard io_and_pipes05 standard io_and_pipes
05 standard io_and_pipes
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bash
 
03 browsing the filesystem
03 browsing the filesystem03 browsing the filesystem
03 browsing the filesystem
 
01 linux history overview
01 linux history overview01 linux history overview
01 linux history overview
 

Recently uploaded

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Recently uploaded (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

09 string processing_with_regex copy

  • 2. Regular Expressions • Regular Expression is a mean for defining text patterns. It is vastly used in various implementation of automatic computing tasks • Regular expressions can be used when working with different programming languages, such as Perl, AWK and TCL or with some of the Linux power tools such as sed, grep, awk, expr and VI • There are two main types of regular expressions usage – Matching – Substitution Note: Regular expression can be also referred as regexp or REGEX
  • 3. Regular Expressions • REGEX are different from the shell’s meta-characters, even though they make use of similar characters; They should always be quoted in order to protect them from the shell. Note: There are some variants and additions in the REGEX syntaxes between the different commands; if something does not work or if in doubt, consult the man pages of that program.
  • 4. Regular Expressions • Below is a list of some of the common REGEX and their values:  . - match any single character.  [list] – matches any single character in the list.  [range] – matches any single character in the range.  [^range] - matches any single character, not in list or range.  * - matches previous character 0 or more times.  {n} – matches previous character n times.  {n,} – matches previous character at least n times.  {n,m} – matches previous character between n and m times.  ^ - matches regex at the start of the line Only.  $ - matches regex at the end of the line Only.  - quote. Cancels the meaning of a meta-character.
  • 5. Regular Expressions | - Logical OR & - Logical AND ! - Logical NOT • Regular Expression parsing is done simply be interpreting each char, from left to right. When matching, each text line will be tested for a match against the Regular Expression every time a new character is being parsed • Each character matches itself, unless it is a meta-character.
  • 6. Regular Expressions • Some examples for REGEX matching: # egrep '^u' /etc/passwd uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin user1:x:500:500::/home/user1:/bin/bash # egrep '^[^a-v]' /etc/passwd webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
  • 7. sed • ‘sed’ is a stream editor, it parses and edit text according to a predefined set of commands • Syntax:  sed [options] ‘command(s)’ [file] • Options:  -i modify the file data  -e adds support for multiple commands  -n do not output lines by default By default, the “sed” command does not change the contents of files; the safer way to make the changes is to redirect the new output, after “sed” has done its trick into a new file.
  • 8. sed • ‘sed’ uses Regular Expression commands to do both matching and text manipulation • Regular Expression commands can be pretty confusing, as the command declaration can be on both sides of the regexp declaration • Syntax:  [command]/regexp/[command][arguments] – ‘/regexp/p’ Print matched text (to be used with ‘-n’) – ‘/regexp/d’ Delete matched text – ‘s/regexp/string/[g]’ Substitute matched text with string
  • 9. sed • ‘sed’ is one of the more complex Linux power tools. For most advanced usages, it has two main competitors: Perl and ‘awk’. Both are fully featured programming languages. • Example # cat file one two three four five six # sed 's/([a-z]*) ([a-z]*) ([a-z]*)/1 SECRET 3/g' file
  • 10. sed • ‘sed’ is one of the more complex Linux power tools. For most advanced usages, it has two main competitors: Perl and ‘awk’. Both are fully featured programming languages. • Example # cat file one two three four five six # sed 's/([a-z]*) ([a-z]*) ([a-z]*)/1 SECRET 3/g' file

Editor's Notes

  1. Discussion: importance of regular expressions for even the most basic automated task Usage in programming languages and IT The difference between Matching and Substitution
  2. Draw: Explanation scheme
  3. Exercise: use egrep with a regular expression to print out all user records for users with name beginning with u or with r
  4. Exercise: use sed to view only the ‘root’ user record from /etc/passwd Exrcise: used sed to print the ‘ etc/shadow/file ’ while removing the ‘ user ’ records
  5. If time permits: show a short example of AWK (use perl in exercise for “fast” students) Exercise for home / later - explain the example