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
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
15
5.8k
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
120
技術的負債の正体を知って向き合う
irof
0
190
Catch Up: Go Style Guide Update
andpad
0
230
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
300
Cursorハンズオン実践!
eltociear
2
1.1k
Le côté obscur des IA génératives
pascallemerrer
0
150
株式会社 Sun terras カンパニーデック
sunterras
0
360
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
1
690
Swift Concurrency - 状態監視の罠
objectiveaudio
2
550
Leading Effective Engineering Teams in the AI Era
addyosmani
7
480
iOSでSVG画像を扱う
kishikawakatsumi
0
110
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4k
Mobile First: as difficult as doing things right
swwweet
225
10k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
Docker and Python
trallard
46
3.6k
Keith and Marios Guide to Fast Websites
keithpitt
411
23k
Why Our Code Smells
bkeepers
PRO
340
57k
Building Adaptive Systems
keathley
44
2.8k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
Automating Front-end Workflow
addyosmani
1371
200k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
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