$30 off During Our Annual Pro Sale. View Details »
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
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.9k
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
120
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
850
WebRTC、 綺麗に見るか滑らかに見るか
sublimer
1
190
チームをチームにするEM
hitode909
0
340
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
510
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
130
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
490
Integrating WordPress and Symfony
alexandresalome
0
160
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
1.2k
手が足りない!兼業データエンジニアに必要だったアーキテクチャと立ち回り
zinkosuke
0
740
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
250
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Balancing Empowerment & Direction
lara
5
800
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
Producing Creativity
orderedlist
PRO
348
40k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
YesSQL, Process and Tooling at Scale
rocio
174
15k
4 Signs Your Business is Dying
shpigford
186
22k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
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