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
130
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
100
Strategies for saying no
aemeredith
0
90
Start your own apprenticeship program
aemeredith
0
170
Story-telling with Git rebase
aemeredith
1
1.2k
Algorithms to live by and why should we care
aemeredith
0
560
Feedback matters
aemeredith
0
280
Two heads are better than one
aemeredith
2
1.3k
Feedback Matters
aemeredith
0
300
How I Learn
aemeredith
0
310
Other Decks in Technology
See All in Technology
プロダクトの不具合傾向分析と改善活動について
masayuki_yamad
0
210
静的解析ツールの刷新に向けた取り組み
suginao
1
150
AWS でのクラウド時代のログ活用
itotsum
1
130
TCPポート使い切り事件
motooka
1
120
React19 β をざっと見る
rakus_fe
0
120
上手く活用すればコスト削減につながる、ONTAPの Temperature Sensitive Storage Efficiency (TSSE) の紹介
non97
0
220
意義から考えるObservability入門 #srenext
stefafafan
2
830
React 19を概念から理解する
uhyo
19
6.3k
Handling Large Data with Python
topspinj
0
150
第34回 中国地方DB勉強会 in 広島_Why DBRE?
tomomo
7
1.8k
組織的なクラウド統制のはじめの一歩_20240529
yhana
0
410
プロファイラを使ってPythonアプリをチューニングしよう
tokibito
2
280
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
423
63k
Thoughts on Productivity
jonyablonski
60
3.9k
Designing with Data
zakiwarfel
96
4.9k
Infographics Made Easy
chrislema
238
18k
Practical Orchestrator
shlominoach
183
9.8k
Building Applications with DynamoDB
mza
88
5.7k
What's in a price? How to price your products and services
michaelherold
238
11k
How to name files
jennybc
65
94k
Designing Experiences People Love
moore
136
23k
The Art of Programming - Codeland 2020
erikaheidi
43
12k
Learning to Love Humans: Emotional Interface Design
aarron
268
39k
Writing Fast Ruby
sferik
623
60k
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