SlideShare a Scribd company logo
1 of 24
Download to read offline
Ruby Regular Expression - Basics
Regular Expression
Historically, regular expressions are one
of computer science's shining examples
of how using good theory leads to good
programs.
Today, regular expressions have also
become a shining example of how
ignoring good theory leads to bad
programs.
What is regular expression
●
Is a notation for describing a set of
character strings
●
sequence of characters within /, /
●
single character within /, / is the simple
regular expression
Ex: /hello world/
What can be done with regular
expression ?
●
Test a string to see whether it matches
a pattern
●
Extract from a string the sections that
match all or part of a pattern
●
Change the string, replacing parts that
match a pattern
Metacharcters
●
Some characters have special meaning
in regular expression
– ., |, (, ), [, ], {, }, +, , ^, $, * and ?
–
●
They don't match themselves
●
To match, escape it with ''
Ex: '*' =~ /*/
Ruby Regular Expressions
●
Uses 'Oniguruma' open source C library
by K. Kosako
●
It also an object, Regexp
●
#{...} expression substitutions in the
pattern
How to create pattern in ruby ?
●
//
Ex: /hello/
●
Regexp.new
Ex: Regexp.new('hello')
●
%r{...}
Ex: %r{mm/dd}
Matching against String
“When a particular string is in the set described
by a regular expression, we often say that the
regular expression matches the string”
●
=~
– Returns matched index / nil
●
!~
– Returns true / false
●
match()
– Method of String & Regexp
– Returns MatchData object / nil
Regular expression options
●
i – case insensitive
●
m – multiline mode
●
x – Extended mode
Metacharacters
●
Period ( . )
– To match any character
– Should be escaped to match literal '.'
Metacharacters
●
Anchors
– To restrict the pattern to match beginning
or end of the line
– ^ - beginning of the line
– $ - end of the line
– A – beginning of the string
– Z – end of the string
Metacharacters
●
Character Class
– Set of characters between [ and ]
– Can have ranges
– Can negate character sets
●
Sequences
d, D, w, W, s, S
Ex:
●
/[dr]ejected/
●
Match digits [0-9]
●
Alphanumeric [A-Za-z0-9]
●
Except digits [^0-9]
●
Str.gsub(/['”]/,'')
Metacharacters
●
Repetition
– r* Matches zero or more occurrences of r
– r+ Matches one or more occurrences of r
– r? Matches zero or one occurrence of r
– r{m,n} Matches at least m and at most n
occurrences of r
– r{m,} Matches at least m occurrences of r
– r{,n} Matches at most n occurrences of r
– r{m } Matches exactly m occurrences of r
Metacharacters
●
Alternation
– |
Ex: /red|blue/
●
Grouping
– Everything within the group is treated as a
single regular expression
– Backreferenced by numbers
Metacharacters
●
Repetition
– r* Matches zero or more occurrences of r
– r+ Matches one or more occurrences of r
– r? Matches zero or one occurrence of r
– r{m,n} Matches at least m and at most n
occurrences of r
– r{m,} Matches at least m occurrences of r
– r{,n} Matches at most n occurrences of r
– r{m } Matches exactly m occurrences of r
Vim Editor - Basics
Vim - Intro
●
Vim is a text editor written by Bram
Moolenaar based on 'vi'
●
The original code for 'vi' was written by
Bill Joy in 1976
●
Originally created for Unix systems
Vim – Modes
●
Normal Mode
– characters you type are commands
– Default mode
●
Insert Mode
– the characters are inserted as text
– I, i, A, a, O, o switch to insert mode
– Escp key is to come back to normal mode
Vim – Manipulation
●
Delete
– d
– dw, dd, D, x, X
●
Copy
– y
– yw, yy, Y
●
Join
– J
●
Paste
– P, p
●
Replace
– r, R
●
Undo & Redo
– u, Ctrl+r
Vim – Navigation
●
h, j, k , l
●
w, b, e
●
0, ^, $
– P, p
●
G, gg
●
% (matches {}()[ ])
●
Ctrl-b, Ctrl-f
●
N G ( got to nth line)
Vim – Search & Replace
●
/pattern
●
?pattern
– N, n
●
:range s/oldpattern/new/options
●
F, f, t, T
Vim – Misc
●
Surrounding
●
Swapcase
●
Vim file +pageno
●
Set nu, spell
●
gf
●
autocomplete
Vim – Exit
●
:q
●
:q!
●
:wq
Thanks

More Related Content

What's hot

Regular expression
Regular expressionRegular expression
Regular expressionLarry Nung
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentationarnolambert
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsMesut Günes
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regexwayn
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular ExpressionMasudul Haque
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsMatt Casto
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionLambert Lum
 
The Power of Regular Expression: use in notepad++
The Power of Regular Expression: use in notepad++The Power of Regular Expression: use in notepad++
The Power of Regular Expression: use in notepad++Anjesh Tuladhar
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular ExpressionsOCSI
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular ExpressionsJesse Anderson
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101Raj Rajandran
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsBrij Kishore
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expressionGagan019
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrepTri Truong
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle databaseAmrit Kaur
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular ExpressionsMukesh Tekwani
 

What's hot (20)

Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Regular expression
Regular expressionRegular expression
Regular expression
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Regular Expression (Regex) Fundamentals
Regular Expression (Regex) FundamentalsRegular Expression (Regex) Fundamentals
Regular Expression (Regex) Fundamentals
 
16 Java Regex
16 Java Regex16 Java Regex
16 Java Regex
 
Java: Regular Expression
Java: Regular ExpressionJava: Regular Expression
Java: Regular Expression
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
The Power of Regular Expression: use in notepad++
The Power of Regular Expression: use in notepad++The Power of Regular Expression: use in notepad++
The Power of Regular Expression: use in notepad++
 
Textpad and Regular Expressions
Textpad and Regular ExpressionsTextpad and Regular Expressions
Textpad and Regular Expressions
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Finaal application on regular expression
Finaal application on regular expressionFinaal application on regular expression
Finaal application on regular expression
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 

Similar to Regular expressions in Ruby and Introduction to Vim

Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Eloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular ExpressionEloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular ExpressionKuyseng Chhoeun
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Ben Brumfield
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingz9819898203
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdfGaneshRaghu4
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and YouJames Armes
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Sandy Smith
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracleLogan Palanisamy
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxKenny (netman)
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionProf. Wim Van Criekinge
 
Matching with Regular Expressions
Matching with Regular ExpressionsMatching with Regular Expressions
Matching with Regular Expressionsprimeteacher32
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with SwiftFatih Nayebi, Ph.D.
 

Similar to Regular expressions in Ruby and Introduction to Vim (20)

Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekingeBioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
Bioinformatics p2-p3-perl-regexes v2013-wim_vancriekinge
 
Eloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular ExpressionEloquent Ruby chapter 4 - Find The Right String with Regular Expression
Eloquent Ruby chapter 4 - Find The Right String with Regular Expression
 
Bioinformatica p2-p3-introduction
Bioinformatica p2-p3-introductionBioinformatica p2-p3-introduction
Bioinformatica p2-p3-introduction
 
Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013Introduction to Regular Expressions RootsTech 2013
Introduction to Regular Expressions RootsTech 2013
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
 
Ruby training day1
Ruby training day1Ruby training day1
Ruby training day1
 
Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014Bioinformatics p2-p3-perl-regexes v2014
Bioinformatics p2-p3-perl-regexes v2014
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
Module 3 - Regular Expressions, Dictionaries.pdf
Module 3 - Regular  Expressions,  Dictionaries.pdfModule 3 - Regular  Expressions,  Dictionaries.pdf
Module 3 - Regular Expressions, Dictionaries.pdf
 
Regular Expressions and You
Regular Expressions and YouRegular Expressions and You
Regular Expressions and You
 
Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014Don't Fear the Regex - CapitalCamp/GovDays 2014
Don't Fear the Regex - CapitalCamp/GovDays 2014
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
Linux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regxLinux fundamental - Chap 06 regx
Linux fundamental - Chap 06 regx
 
Bioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introductionBioinformatica 06-10-2011-p2 introduction
Bioinformatica 06-10-2011-p2 introduction
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Matching with Regular Expressions
Matching with Regular ExpressionsMatching with Regular Expressions
Matching with Regular Expressions
 
07. haskell Membership
07. haskell Membership07. haskell Membership
07. haskell Membership
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 

Recently uploaded

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Recently uploaded (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Regular expressions in Ruby and Introduction to Vim

  • 2. Regular Expression Historically, regular expressions are one of computer science's shining examples of how using good theory leads to good programs. Today, regular expressions have also become a shining example of how ignoring good theory leads to bad programs.
  • 3. What is regular expression ● Is a notation for describing a set of character strings ● sequence of characters within /, / ● single character within /, / is the simple regular expression Ex: /hello world/
  • 4. What can be done with regular expression ? ● Test a string to see whether it matches a pattern ● Extract from a string the sections that match all or part of a pattern ● Change the string, replacing parts that match a pattern
  • 5. Metacharcters ● Some characters have special meaning in regular expression – ., |, (, ), [, ], {, }, +, , ^, $, * and ? – ● They don't match themselves ● To match, escape it with '' Ex: '*' =~ /*/
  • 6. Ruby Regular Expressions ● Uses 'Oniguruma' open source C library by K. Kosako ● It also an object, Regexp ● #{...} expression substitutions in the pattern
  • 7. How to create pattern in ruby ? ● // Ex: /hello/ ● Regexp.new Ex: Regexp.new('hello') ● %r{...} Ex: %r{mm/dd}
  • 8. Matching against String “When a particular string is in the set described by a regular expression, we often say that the regular expression matches the string” ● =~ – Returns matched index / nil ● !~ – Returns true / false ● match() – Method of String & Regexp – Returns MatchData object / nil
  • 9. Regular expression options ● i – case insensitive ● m – multiline mode ● x – Extended mode
  • 10. Metacharacters ● Period ( . ) – To match any character – Should be escaped to match literal '.'
  • 11. Metacharacters ● Anchors – To restrict the pattern to match beginning or end of the line – ^ - beginning of the line – $ - end of the line – A – beginning of the string – Z – end of the string
  • 12. Metacharacters ● Character Class – Set of characters between [ and ] – Can have ranges – Can negate character sets ● Sequences d, D, w, W, s, S Ex: ● /[dr]ejected/ ● Match digits [0-9] ● Alphanumeric [A-Za-z0-9] ● Except digits [^0-9] ● Str.gsub(/['”]/,'')
  • 13. Metacharacters ● Repetition – r* Matches zero or more occurrences of r – r+ Matches one or more occurrences of r – r? Matches zero or one occurrence of r – r{m,n} Matches at least m and at most n occurrences of r – r{m,} Matches at least m occurrences of r – r{,n} Matches at most n occurrences of r – r{m } Matches exactly m occurrences of r
  • 14. Metacharacters ● Alternation – | Ex: /red|blue/ ● Grouping – Everything within the group is treated as a single regular expression – Backreferenced by numbers
  • 15. Metacharacters ● Repetition – r* Matches zero or more occurrences of r – r+ Matches one or more occurrences of r – r? Matches zero or one occurrence of r – r{m,n} Matches at least m and at most n occurrences of r – r{m,} Matches at least m occurrences of r – r{,n} Matches at most n occurrences of r – r{m } Matches exactly m occurrences of r
  • 16. Vim Editor - Basics
  • 17. Vim - Intro ● Vim is a text editor written by Bram Moolenaar based on 'vi' ● The original code for 'vi' was written by Bill Joy in 1976 ● Originally created for Unix systems
  • 18. Vim – Modes ● Normal Mode – characters you type are commands – Default mode ● Insert Mode – the characters are inserted as text – I, i, A, a, O, o switch to insert mode – Escp key is to come back to normal mode
  • 19. Vim – Manipulation ● Delete – d – dw, dd, D, x, X ● Copy – y – yw, yy, Y ● Join – J ● Paste – P, p ● Replace – r, R ● Undo & Redo – u, Ctrl+r
  • 20. Vim – Navigation ● h, j, k , l ● w, b, e ● 0, ^, $ – P, p ● G, gg ● % (matches {}()[ ]) ● Ctrl-b, Ctrl-f ● N G ( got to nth line)
  • 21. Vim – Search & Replace ● /pattern ● ?pattern – N, n ● :range s/oldpattern/new/options ● F, f, t, T
  • 22. Vim – Misc ● Surrounding ● Swapcase ● Vim file +pageno ● Set nu, spell ● gf ● autocomplete