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
170
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
180
Strategies for saying no
aemeredith
1
150
Start your own apprenticeship program
aemeredith
0
250
Story-telling with Git rebase
aemeredith
1
1.5k
Algorithms to live by and why should we care
aemeredith
0
690
Feedback matters
aemeredith
0
370
Two heads are better than one
aemeredith
2
1.6k
Feedback Matters
aemeredith
0
380
How I Learn
aemeredith
0
500
Other Decks in Technology
See All in Technology
Open Table Format (OTF) が必要になった背景とその機能 (2025.10.28)
simosako
2
350
dbtとAIエージェントを組み合わせて見えたデータ調査の新しい形
10xinc
5
1.1k
re:Inventに行くまでにやっておきたいこと
nagisa53
0
510
アウトプットから始めるOSSコントリビューション 〜eslint-plugin-vueの場合〜 #vuefes
bengo4com
3
1.8k
もう外には出ない。より快適なフルリモート環境を目指して
mottyzzz
13
11k
入院医療費算定業務をAIで支援する:包括医療費支払い制度とDPCコーディング (公開版)
hagino3000
0
110
[re:Inent2025事前勉強会(有志で開催)] re:Inventで見つけた人生をちょっと変えるコツ
sh_fk2
1
540
AI機能プロジェクト炎上の 3つのしくじりと学び
nakawai
0
120
「タコピーの原罪」から学ぶ間違った”支援” / the bad support of Takopii
piyonakajima
0
150
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
14
82k
OSSで50の競合と戦うためにやったこと
yamadashy
3
1k
GraphRAG グラフDBを使ったLLM生成(自作漫画DBを用いた具体例を用いて)
seaturt1e
1
150
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
190
55k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
890
The Language of Interfaces
destraynor
162
25k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.7k
Writing Fast Ruby
sferik
630
62k
Practical Orchestrator
shlominoach
190
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
Gamification - CAS2011
davidbonilla
81
5.5k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Scaling GitHub
holman
463
140k
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