$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Regular Expressions Basics Lesson for Ada Academy
Search
nellshamrell
September 26, 2014
Technology
0
46
Regular Expressions Basics Lesson for Ada Academy
nellshamrell
September 26, 2014
Tweet
Share
Other Decks in Technology
See All in Technology
因果AIへの招待
sshimizu2006
0
980
SREには開発組織全体で向き合う
koh_naga
0
360
.NET 10の概要
tomokusaba
0
110
NIKKEI Tech Talk #41: セキュア・バイ・デザインからクラウド管理を考える
sekido
PRO
0
130
MLflowで始めるプロンプト管理、評価、最適化
databricksjapan
1
250
コンテキスト情報を活用し個社最適化されたAI Agentを実現する4つのポイント
kworkdev
PRO
1
1.5k
regrowth_tokyo_2025_securityagent
hiashisan
0
250
S3を正しく理解するための内部構造の読解
nrinetcom
PRO
2
130
Microsoft Agent 365 についてゆっくりじっくり理解する!
skmkzyk
0
370
OCI Oracle Database Services新機能アップデート(2025/09-2025/11)
oracle4engineer
PRO
1
210
AI-DLCを現場にインストールしてみた:プロトタイプ開発で分かったこと・やめたこと
recruitengineers
PRO
2
150
AI駆動開発の実践とその未来
eltociear
0
120
Featured
See All Featured
Navigating Team Friction
lara
191
16k
Fireside Chat
paigeccino
41
3.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Visualization
eitanlees
150
16k
Embracing the Ebb and Flow
colly
88
4.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Designing for Performance
lara
610
69k
Transcript
REGULAR EXPRESSIONS Nell Shamrell @nellshamrell
What is a regular expression? It’s a pattern.
How do you make a regular expression? /RegularExpression/
What can you do with a regular expression?
Test Extract Change
Test Extract Change
Test Extract Change
Testing a String
“Use the force”
/force/ “Use the force”
=~
/force/ =~ “Use the force”
“Use the force” =~ /force/
/force/ =~ “Use the force” => 8
/dark side/ !~ “Use the force”
/dark side/ !~ “Use the force” => true
MatchData
match
string = “The force will be with you always.”
string = “The force will be with you always.” m
= /force/.match(string)
string = “The force will be with you always.” m
= /force/.match(string) => #<MatchData “force” >
What can you do with MatchData?
m = /force/.match(string)
m = /force/.match(string) m.to_s
m = /force/.match(string) m.to_s => “force”
m = /force/.match(string)
m = /force/.match(string) m.pre_match
m = /force/.match(string) m.pre_match => “The ”
m = /force/.match(string)
m = /force/.match(string) m.post_match
m = /force/.match(string) m.post_match => “ will be with you
always ”
Email Validation
[email protected]
Rubular
Alternation /nell | renee /
. * any single character character can appear any number
of times
/.*/ Matches ANYTHING
Range [a-d] [1-4]
\w stands for any word character same as [a-zA-Z0-9_]
+ character must appear one or more times
None
Extracting Strings
\d stands for any digit same as [0-9]
\d{3} looks for exactly 3 digits
? makes a character optional
Changing a String
string = “Renee is presenting to the class right now.
Renee is presenting on regular expressions.”
sub(/regex/, “text”)
string = “Renee is presenting to the class right now.
Renee is presenting on regular expressions.”
string = “Renee is presenting to the class right now.
Renee is presenting on regular expressions.” new = string.sub(/Renee/, “Nell”)
new = string.sub(/Renee/, “Nell”) => “Nell is presenting to the
class right now. Renee is presenting on regular expressions.”
gsub(/regex/, “text”)
new = string.gsub(/Renee/, “Nell”)
=> “Nell is presenting to the class right now. Nell
is presenting on regular expressions.” new = string.gsub(/Renee/, “Nell”)
string.gsub!(/Renee/, “Nell”)
Welcome to the world of regular expressions!
https://gist.github.com/ nellshamrell/6938008 Resources
Contact Info Nell Shamrell @nellshamrell
[email protected]