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
120
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
Strategies for saying no
aemeredith
0
85
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
540
Feedback matters
aemeredith
0
270
Two heads are better than one
aemeredith
2
1.3k
Feedback Matters
aemeredith
0
290
How I Learn
aemeredith
0
280
Just in time RailsIsrael
aemeredith
1
180
Other Decks in Technology
See All in Technology
沒想過的前端錯誤處理可能比你有做的還多
line_developers_tw
PRO
0
2k
戦略的DDDを実践するための跳躍力 / OOC 2024
pictiny
6
3.9k
複数の LLM モデルを扱う上で直面した辛みまとめ
kazuyaseki
1
230
LLMプロダクト事業の立ち上げにおける挑戦
layerx
PRO
7
1.4k
10分でわかるfreeeのQA
freee
0
230
マイクロサービス環境におけるDB戦略 in DMMプラットフォーム
pospome
11
3k
HoneycombとOpenTelemetryでオブザーバビリティに入門してみる
sumiren
2
150
Getting started with controlling LEGO using Swift
hcrane
0
130
AMLD 2024 - Build Your Own GPT
donlelef
1
260
技術イベントはなんとかひねり出す 日経の技術広報の取り組み/techpr3
nishiuma
0
220
2023 Japan AWS Jr.Championsに選出されての振り返りとこれから
hiropy877
1
130
統計的学習理論読み Chapter 1
kmatsui
3
770
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
11
1.4k
Building Your Own Lightsaber
phodgson
97
5.6k
KATA
mclloyd
14
11k
Mobile First: as difficult as doing things right
swwweet
215
8.5k
Unsuck your backbone
ammeep
661
56k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
240
1.2M
Art, The Web, and Tiny UX
lynnandtonic
288
19k
The Invisible Side of Design
smashingmag
293
49k
RailsConf 2023
tenderlove
0
510
The Art of Programming - Codeland 2020
erikaheidi
40
12k
A Philosophy of Restraint
colly
195
15k
Building Flexible Design Systems
yeseniaperezcruz
317
37k
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