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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Fluid Templating in TYPO3 14
s2b
0
130
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
3
280
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
4
240
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
240
組織で育むオブザーバビリティ
ryota_hnk
0
170
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
100
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.3k
AIエージェントの設計で注意するべきポイント6選
har1101
7
3.4k
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
2
2.3k
Designing Powerful Visuals for Engaging Learning
tmiket
0
220
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
420
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
The Pragmatic Product Professional
lauravandoore
37
7.1k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
280
Navigating Weather and Climate Data
rabernat
0
100
Abbi's Birthday
coloredviolet
1
4.7k
Code Review Best Practice
trishagee
74
20k
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