Many of us approach regular expressions with a certain fear and trepidation, using them only when absolutely necessary. We can get by when we need to use them, but we hesitate to dive any deeper into their cryptic world. Ruby has so much more to offer us. This talk showcases the incredible power of Ruby and the Oniguruma regex library Ruby runs on. It takes you on a journey beneath the surface, exploring the beauty, elegance, and power of regular expressions. You will discover the flexible, dynamic, and eloquent ways to harness this beauty and power in your own code.
Automating Google Workspace (GWS) & more with Apps Script
Beneath the Surface: Regular Expressions in Ruby
1. Photo By Mr. Christopher Thomas
Creative Commons Attribution-ShareALike 2.0 Generic License
Beneath the
Surface
Embracing the True Power of
Regular Expressions in Ruby
@nellshamrell
119. Find first letter of string and
capitalize it
snake_case to CamelCase
120. Find first letter of string and
capitalize it
Find any character that follows
an underscore and capitalize it
snake_case to CamelCase
121. Find first letter of string and
capitalize it
Find any character that follows an
underscore and capitalize it
Remove underscores
snake_case to CamelCase
122. Find first letter of string and
capitalize it
snake_case to CamelCase
123. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
.upcase_chars(ʺ″methodʺ″)
result.should == ʺ″Methodʺ″
case_converter_spec.rb
before(:each) do
end
@case_converter = CaseConverter.new
124. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
.upcase_chars(ʺ″methodʺ″)
result.should == ʺ″Methodʺ″
case_converter_spec.rb
before(:each) do
end
@case_converter = CaseConverter.new
125. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
.upcase_chars(ʺ″methodʺ″)
result.should == ʺ″Methodʺ″
case_converter_spec.rb
before(:each) do
end
@case_converter = CaseConverter.new
131. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
result.should == ʺ″_Methodʺ″
case_converter_spec.rb
.upcase_chars(ʺ″_methodʺ″)
132. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
result.should == ʺ″_Methodʺ″
case_converter_spec.rb
.upcase_chars(ʺ″_methodʺ″)
133. it ʺ″capitalizes the first letterʺ″ do
end
result = @case_converter
result.should == ʺ″_Methodʺ″
case_converter_spec.rb
.upcase_chars(ʺ″_methodʺ″)
Spec Fails!
141. Find any character that follows an
underscore and capitalize it
snake_case to CamelCase
142. it ʺ″capitalizes letters after an underscoreʺ″ do
end
result = @case_converter
result.should == ʺ″Some_Methodʺ″
case_converter_spec.rb
.upcase_chars(ʺ″some_methodʺ″)
143. it ʺ″capitalizes letters after an underscoreʺ″ do
end
result = @case_converter
result.should == ʺ″Some_Methodʺ″
case_converter_spec.rb
.upcase_chars(ʺ″some_methodʺ″)
150. it ʺ″removes underscoresʺ″ do
end
result = @case_converter
result.should == ʺ″somemethodʺ″
case_converter_spec.rb
.rmv_underscores(ʺ″some_methodʺ″)
151. it ʺ″removes underscoresʺ″ do
end
result = @case_converter
result.should == ʺ″somemethodʺ″
case_converter_spec.rb
.rmv_underscores(ʺ″some_methodʺ″)
152. it ʺ″removes underscoresʺ″ do
end
result = @case_converter
result.should == ʺ″somemethodʺ″
case_converter_spec.rb
.rmv_underscores(ʺ″some_methodʺ″)
158. it ʺ″converts snake_case to CamelCaseʺ″ do
end
result = @case_converter
result.should == ʺ″SomeMethodʺ″
case_converter_spec.rb
.snake_to_camel(ʺ″some_methodʺ″)
159. it ʺ″converts snake_case to CamelCaseʺ″ do
end
result = @case_converter
result.should == ʺ″SomeMethodʺ″
case_converter_spec.rb
.snake_to_camel(ʺ″some_methodʺ″)
160. it ʺ″converts snake_case to CamelCaseʺ″ do
end
result = @case_converter
result.should == ʺ″SomeMethodʺ″
case_converter_spec.rb
.snake_to_camel(ʺ″some_methodʺ″)