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
160
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
130
Start your own apprenticeship program
aemeredith
0
210
Story-telling with Git rebase
aemeredith
1
1.4k
Algorithms to live by and why should we care
aemeredith
0
630
Feedback matters
aemeredith
0
340
Two heads are better than one
aemeredith
2
1.5k
Feedback Matters
aemeredith
0
350
How I Learn
aemeredith
0
430
Other Decks in Technology
See All in Technology
Amazon Q Developerの無料利用枠を使い倒してHello worldを表示させよう!
nrinetcom
PRO
2
120
30→150人のエンジニア組織拡大に伴うアジャイル文化を醸成する役割と取り組みの変化
nagata03
0
370
プルリクエストレビューを終わらせるためのチーム体制 / The Team for Completing Pull Request Reviews
nekonenene
3
1.7k
【Forkwell】「正しく」失敗できるチームを作る──現場のリーダーのための恐怖と不安を乗り越える技術 - FL#83 / A team that can fail correctly by forkwell
i35_267
2
130
データモデルYANGの処理系を再発明した話
tjmtrhs
0
360
役員・マネージャー・著者・エンジニアそれぞれの立場から見たAWS認定資格
nrinetcom
PRO
5
6.9k
人生を左右する「即答」のススメ: 一瞬の判断を間違えないためにするべきこと
takasyou
2
200
AI Agent時代なのでAWSのLLMs.txtが欲しい!
watany
3
380
ライフステージの変化を乗り越える 探索型のキャリア選択
tenshoku_draft
2
150
AIエージェント元年@日本生成AIユーザ会
shukob
1
260
エンジニアのキャリアパスと、 その中で自分が大切にしていること
noteinc
3
620
JavaにおけるNull非許容性
skrb
2
2.7k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
440
Bash Introduction
62gerente
611
210k
Site-Speed That Sticks
csswizardry
4
420
Making Projects Easy
brettharned
116
6k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Statistics for Hackers
jakevdp
797
220k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
11
1.3k
Music & Morning Musume
bryan
46
6.4k
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