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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
140
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
310
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
120
CSC307 Lecture 12
javiergs
PRO
0
450
Metaprogramming isn't real, it can't hurt you
okuramasafumi
0
130
The Ralph Wiggum Loop: First Principles of Autonomous Development
sembayui
0
3.7k
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
2
1k
並行開発のためのコードレビュー
miyukiw
2
2k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
200
AWS Infrastructure as Code の新機能 2025 総まとめ~ SA 4人による怒涛のデモ祭り ~
konokenj
8
2.1k
Oxlint JS plugins
kazupon
1
1.1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
310
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
570
New Earth Scene 8
popppiees
1
1.6k
Abbi's Birthday
coloredviolet
2
5k
Automating Front-end Workflow
addyosmani
1371
200k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
170
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
[SF Ruby Conf 2025] Rails X
palkan
2
790
30 Presentation Tips
portentint
PRO
1
240
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
220
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