Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Regular Expressions with Ruby
Search
Elle Meredith
April 03, 2014
Technology
1
190
Regular Expressions with Ruby
What Do You Know? Sydney, 03 April, 2014
Elle Meredith
April 03, 2014
Tweet
Share
More Decks by Elle Meredith
See All by Elle Meredith
Exploring anti-patterns in Rails
aemeredith
2
250
Strategies for saying no
aemeredith
1
190
Start your own apprenticeship program
aemeredith
0
280
Story-telling with Git rebase
aemeredith
1
1.6k
Algorithms to live by and why should we care
aemeredith
0
740
Feedback matters
aemeredith
0
390
Two heads are better than one
aemeredith
2
1.6k
Feedback Matters
aemeredith
0
410
How I Learn
aemeredith
0
550
Other Decks in Technology
See All in Technology
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.4k
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
630
Greatest Disaster Hits in Web Performance
guaca
0
260
Introduction to Bill One Development Engineer
sansan33
PRO
0
360
Tebiki Engineering Team Deck
tebiki
0
24k
Oracle Cloud Observability and Management Platform - OCI 運用監視サービス概要 -
oracle4engineer
PRO
2
14k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
68k
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.4k
仕様書駆動AI開発の実践: Issue→Skill→PRテンプレで 再現性を作る
knishioka
2
670
AzureでのIaC - Bicep? Terraform? それ早く言ってよ会議
torumakabe
1
570
Context Engineeringの取り組み
nutslove
0
360
AWS Network Firewall Proxyを触ってみた
nagisa53
1
240
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.5k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
230
The Cult of Friendly URLs
andyhume
79
6.8k
Un-Boring Meetings
codingconduct
0
200
Google's AI Overviews - The New Search
badams
0
910
sira's awesome portfolio website redesign presentation
elsirapls
0
150
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
37k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Designing for Timeless Needs
cassininazir
0
130
Statistics for Hackers
jakevdp
799
230k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Transcript
Regular Expressions with Ruby Elle Meredith – @aemeredith
Test Extract Change
/fox/ =~ "The quick brown fox" Basic Matching
/fox/ =~ "The quick brown fox" => 16 Basic Matching
/cat/ =~ "The quick brown fox" => nil Basic Matching
/cat/ !~ "The quick brown fox" => true Basic Matching
MatchData string = "The quick brown fox jumps over the
lazy dog”
MatchData string = "The quick brown fox jumps over the
lazy dog” ! matchdata = string.match /fox/ => #<MatchData "fox">
MatchData matchdata.to_s => "fox"
MatchData matchdata.pre_match => "The quick brown "
MatchData matchdata.post_match => " jumps over the lazy dog"
Captures string = "03APR2014" ! string.match /\D{3}/
Captures string = "03APR2014" ! string.match /\D{3}/
Captures string = "03APR2014" ! string.match /\D{3}/
Captures string = "03APR2014" ! string.match /\D{3}/ => #<MatchData "APR">
Captures md = string.match /(.*)(\D{3})(.*)/
Captures md = string.match /(.*)(\D{3})(.*)/
Captures md = string.match /(.*)(\D{3})(.*)/
Captures md = string.match /(.*)(\D{3})(.*)/ => #<MatchData "03APR2014" 1:"03" 2:"APR"
3:"2014">
Captures md.captures => ["03", "APR", "2014"]
Captures md = string.match /(.*)(\D{3})(.*)/ => #<MatchData "03APR2014" 1:"03" 2:"APR"
3:"2014">
Captures md[1] => "03" md[2] => "APR" md[3] => "2014"
Named Captures md = string.match /(?<day>.*)(? <month>\D{3})(?<year>.*)/ => #<MatchData "03APR2014"
day:"03" month:"APR" year:"2014">
Named Captures md = string.match /(?<day>.*)(? <month>\D{3})(?<year>.*)/ => #<MatchData "03APR2014"
day:"03" month:"APR" year:"2014">
Named Captures md = string.match /(?<day>.*)(? <month>\D{3})(?<year>.*)/ => #<MatchData "03APR2014"
day:"03" month:"APR" year:"2014">
Named Captures md = string.match /(?<day>.*)(? <month>\D{3})(?<year>.*)/ => #<MatchData "03APR2014"
day:"03" month:"APR" year:"2014">
Named Captures md['day'] => "03"
Look Around string = ''' I love my job, I
love the pay! I love it more and more each day. I love my boss, he is the best! I love his boss and all the rest. '''
Look Around string.scan /love my/ => ["love my", "love my”]
Positive Lookahead string.scan /love my (?=job)/ => ["love my "]
Changing things string.gsub(/love/, 'hate')
Changing things string.gsub(/love/, 'hate') => "\nI hate my job, I
hate the pay! \nI hate it more and more each day.\nI hate my boss, he is the best!\nI hate his boss and all the rest.\n"
Changing things string.gsub!(/\she/, ' she').gsub!(/ his/, 'her')
Changing things string.gsub!(/\she/, ' she').gsub!(/ his/, 'her')
Changing things string.gsub!(/\she/, ' she').gsub!(/ his/, ‘her') => "\nI love
my job, I love the pay! \nI love it more and more each day. \nI love my boss, she is the best!\nI love her boss and all the rest.\n"
None
Regular Expressions with Ruby Elle Meredith – @aemeredith