Slide 1

Slide 1 text

Don’t worry, there are only four. Fear Me Not Tips for Conquering Regular Expressions

Slide 2

Slide 2 text

Contrary to popular opinion, Regex doesn’t have to make you feel like this => Popular Opinion

Slide 3

Slide 3 text

Do I need help?

Slide 4

Slide 4 text

Do I need help? My name is Dana and I like Regular Expressions

Slide 5

Slide 5 text

Do I need help? My name is Dana and I like Regular Expressions It’s been two days since my last Regular Expression

Slide 6

Slide 6 text

When is the end really the end?

Slide 7

Slide 7 text

When is the end really the end? data[/\d+$/] # => "10"

Slide 8

Slide 8 text

When is the end really the end? data[/\d+$/] # => "10" attendance = "Women = 10 Men = 215 Total = 225 "

Slide 9

Slide 9 text

When is the end really the end? data[/\d+$/] # => "10" data[/\d+\z/] # => nil attendance = "Women = 10 Men = 215 Total = 225 "

Slide 10

Slide 10 text

When is the end really the end? data[/\d+$/] # => "10" data[/\d+\z/] # => nil data[/\d+\Z/] # => "225" attendance = "Women = 10 Men = 215 Total = 225 "

Slide 11

Slide 11 text

In Ruby dummy talk, please

Slide 12

Slide 12 text

In Ruby dummy talk, please Symbol WTF?

Slide 13

Slide 13 text

In Ruby dummy talk, please Symbol WTF? ^ Matches the beginning of any line - 100 lines means 100 matches

Slide 14

Slide 14 text

In Ruby dummy talk, please Symbol WTF? ^ Matches the beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match

Slide 15

Slide 15 text

In Ruby dummy talk, please Symbol WTF? ^ Matches the beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches

Slide 16

Slide 16 text

In Ruby dummy talk, please Symbol WTF? ^ Matches the beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches \z Matches the end of the string - at most 1 match

Slide 17

Slide 17 text

In Ruby dummy talk, please Symbol WTF? ^ Matches the beginning of any line - 100 lines means 100 matches \A Matches the beginning of the string - at most 1 match $ Matches the end of any line - 100 lines means 100 matches \z Matches the end of the string - at most 1 match \Z Matches the end of the string or just before the last \n - at most 1 match

Slide 18

Slide 18 text

Getting exactly what I want

Slide 19

Slide 19 text

Getting exactly what I want ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray.", "He lives in Castle Grayskull."]

Slide 20

Slide 20 text

Getting exactly what I want ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray.", "He lives in Castle Grayskull."] /(\W|\A)gray(\W|\Z)/i

Slide 21

Slide 21 text

Getting exactly what I want ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray.", "He lives in Castle Grayskull."] /(\W|\A)gray(\W|\Z)/i /\bGray\b/i

Slide 22

Slide 22 text

Getting exactly what I want ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray.", "He lives in Castle Grayskull."] /(\W|\A)gray(\W|\Z)/i /\bGray\b/i ["Gray is a great color.", "I like gray things.", "I’m hung up on a guy named Gray."]

Slide 23

Slide 23 text

Let’s discuss our differences What’s the difference between this - ( ... ) ! ! and this? - (?: ... )

Slide 24

Slide 24 text

Let’s discuss our differences What’s the difference between this - ( ... ) ! ! and this? - (?: ... ) phone = "123-456-7890" phone =~ /\A(\d+)-(\d+)-(\d+)\z/ puts "#{$1}#{$2}#{$3}" ! # >> 1234567890

Slide 25

Slide 25 text

Let’s discuss our differences What’s the difference between this - ( ... ) ! ! and this? - (?: ... ) phone = "123-456-7890" phone =~ /\A(\d+)-(\d+)-(\d+)\z/ puts "#{$1}#{$2}#{$3}" ! # >> 1234567890 name = "James Edward Gray II" name =~ /\A(\w+)(?:\s\w+)?\s(\w+)/ puts "#{$1} #{$2}" ! # >> James Gray

Slide 26

Slide 26 text

When you can’t make up your mind Sometimes you just can’t decide exactly what you want

Slide 27

Slide 27 text

When you can’t make up your mind Sometimes you just can’t decide exactly what you want /(42|41|40|...)/

Slide 28

Slide 28 text

When you can’t make up your mind Sometimes you just can’t decide exactly what you want /(42|41|40|...)/ /[0-9]/

Slide 29

Slide 29 text

When you can’t make up your mind Sometimes you just can’t decide exactly what you want /(42|41|40|...)/ /[0-9]/ /[1-3]?[0-9]/

Slide 30

Slide 30 text

When you can’t make up your mind Sometimes you just can’t decide exactly what you want /(42|41|40|...)/ /[0-9]/ /[1-3]?[0-9]/ /(4[0-2]|[1-3]?[0-9])/

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

"Fear Regex".sub!(/\AFear\b/, "Embrace")