Named Captures
md = string.match /(?.*)(?
\D{3})(?.*)/
=> #
Slide 24
Slide 24 text
Named Captures
md = string.match /(?.*)(?
\D{3})(?.*)/
=> #
Slide 25
Slide 25 text
Named Captures
md = string.match /(?.*)(?
\D{3})(?.*)/
=> #
Slide 26
Slide 26 text
Named Captures
md = string.match /(?.*)(?
\D{3})(?.*)/
=> #
Slide 27
Slide 27 text
Named Captures
md['day']
=> "03"
Slide 28
Slide 28 text
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.
'''
Slide 29
Slide 29 text
Look Around
string.scan /love my/
=> ["love my", "love my”]
Slide 30
Slide 30 text
Positive Lookahead
string.scan /love my (?=job)/
=> ["love my "]
Slide 31
Slide 31 text
Changing things
string.gsub(/love/, 'hate')
Slide 32
Slide 32 text
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"
Slide 33
Slide 33 text
Changing things
string.gsub!(/\she/, ' she').gsub!(/
his/, 'her')
Slide 34
Slide 34 text
Changing things
string.gsub!(/\she/, ' she').gsub!(/
his/, 'her')
Slide 35
Slide 35 text
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"
Slide 36
Slide 36 text
No content
Slide 37
Slide 37 text
Regular Expressions
with Ruby
Elle Meredith – @aemeredith