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
150
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
1
150
Strategies for saying no
aemeredith
1
120
Start your own apprenticeship program
aemeredith
0
190
Story-telling with Git rebase
aemeredith
1
1.4k
Algorithms to live by and why should we care
aemeredith
0
610
Feedback matters
aemeredith
0
330
Two heads are better than one
aemeredith
2
1.4k
Feedback Matters
aemeredith
0
340
How I Learn
aemeredith
0
410
Other Decks in Technology
See All in Technology
月間60万ユーザーを抱える 個人開発サービス「Walica」の 技術スタック変遷
miyachin
1
130
Bring Your Own Container: When Containers Turn the Key to EDR Bypass/byoc-avtokyo2024
tkmru
0
840
OPENLOGI Company Profile
hr01
0
58k
Oracle Exadata Database Service(Dedicated Infrastructure):サービス概要のご紹介
oracle4engineer
PRO
0
12k
Godot Engineについて調べてみた
unsoluble_sugar
0
370
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
150
チームが毎日小さな変化と適応を続けたら1年間でスケール可能なアジャイルチームができた話 / Building a Scalable Agile Team
kakehashi
2
230
深層学習と3Dキャプチャ・3Dモデル生成(土木学会応用力学委員会 応用数理・AIセミナー)
pfn
PRO
0
460
.NET AspireでAzure Functionsやクラウドリソースを統合する
tsubakimoto_s
0
180
comilioとCloudflare、そして未来へと向けて
oliver_diary
6
440
あなたの人生も変わるかも?AWS認定2つで始まったウソみたいな話
iwamot
3
830
Copilotの力を実感!3ヶ月間の生成AI研修の試行錯誤&成功事例をご紹介。果たして得たものとは・・?
ktc_shiori
0
340
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Navigating Team Friction
lara
183
15k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7.1k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Facilitating Awesome Meetings
lara
51
6.2k
RailsConf 2023
tenderlove
29
970
Why Our Code Smells
bkeepers
PRO
335
57k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Thoughts on Productivity
jonyablonski
68
4.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
A better future with KSS
kneath
238
17k
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