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
Readable Regexps With Rrrex
Search
Ian Young
March 03, 2011
Programming
0
36
Readable Regexps With Rrrex
Building regular expressions using language - introducing a Ruby DSL I built.
Ian Young
March 03, 2011
Tweet
Share
More Decks by Ian Young
See All by Ian Young
The Firewall Also Gazes Into You
iangreenleaf
0
30
The Future of the Front End, or: How I Learned to Stop Worrying and Love JavaScript
iangreenleaf
0
59
Other Decks in Programming
See All in Programming
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1k
CSC307 Lecture 04
javiergs
PRO
0
660
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
160
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.4k
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
260
Grafana:建立系統全知視角的捷徑
blueswen
0
330
AI巻き込み型コードレビューのススメ
nealle
1
150
CSC307 Lecture 07
javiergs
PRO
0
550
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
Data-Centric Kaggle
isax1015
2
770
CSC307 Lecture 02
javiergs
PRO
1
770
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
900
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
The agentic SEO stack - context over prompts
schlessera
0
630
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
180
The Cost Of JavaScript in 2023
addyosmani
55
9.5k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
180
Un-Boring Meetings
codingconduct
0
200
Design in an AI World
tapps
0
140
Being A Developer After 40
akosma
91
590k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
Transcript
Readable Regexps With TRegexp github.com/iangreenleaf @iangreenleaf blog.iangreenleaf.com
self.inspect
Ian Young
Used to do PHP
Rails is much better
work for AMCO Online (huzzah)
2 SDRuby meetings (including this one)
TRegexp
Why?
Because I can
Because I love regexps
...but...
/^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\
What if we used words?
less compact
but friendlier
Examples!
"Your string" =~ /string/
"Your string".rmatch? do "string" end
"abc".rmatch? { "ab" + "c" }
"abc".rmatch? { "xyz".or "abc" }
Ever tried to search for "&"?
"symbols.*&+galore".rmatch? { ".*&+" }
Precedence
"abc".rmatch? { "ab" + ( "z".or "c" ) }
Repetition
"aaa".rmatch? { 1.or_more "a" } "aaa".rmatch? { 5.or_less "a" }
"aaa".rmatch? { 3.exactly "a" } "aaa".rmatch? { (1..5).of "a" }
"aaa".rmatch? { 0.or_more "a" } "aaa".rmatch? { any "a" }
"aaa".rmatch? { 1.or_more "a" } "aaa".rmatch? { some "a" }
Character sets
"abc1234.&*".rmatch? { 10.exactly any_char }
"abc".rmatch? { 3.exactly letter }
"1234".rmatch? { 4.exactly digit }
"abc_123".rmatch? { 7.exactly word_char }
" ".rmatch? { whitespace }
"abc".rmatch? { 3.exactly "a".."c" }
Negation
"x".rmatch? { word_char.not "x" } # => nil "y".rmatch? {
word_char.not "x" }
"x".rmatch? { _not "x" } # => nil "y".rmatch? {
_not "x" }
Grouping
Works the old way
match = "abc".rmatch do group( "a" + group( "b" )
) + "c" end match.to_a #=> [ "abc", "ab", "b" ]
Named groups
match = "abcde".rmatch? do group( :word, any( word_char ) )
end match[ :word ] #=> "abcde"
Or use blocks
match = "abcde".rmatch? do group :word do any word_char end
end match[ :word ] #=> "abcde"
order = "1234567890 Central Processing" match = order.rmatch? do group
:serial do some digit end \ + some whitespace + \ group :source do any any_char end end puts "Order #" + match[ :serial ] puts "Shipped from " + match[ :source ]
Apply brakes
"experimental"
Monkey patches one or two teeny tiny unimportant little core
libs
fixnum.rb range.rb string.rb
Refinements will make this awesome
Now what?
It turned out pretty cool
Need a better name
Could add more syntax
Taking suggestions
def zero_width_positive_lookbehind ... end
No.
Kiddie pool?
Other applications?
kthx github.com/iangreenleaf @iangreenleaf blog.iangreenleaf.com