Other Software > Developer's Corner
regular expressions 101
(1/1)
phitsc:
While working with regular expressions today I stumbled over regular expressions 101. Not only does it test your regular expression as you type, but it also picks it apart and explains it to you piece by piece. Amazing!
wraith808:
There's also https://www.debuggex.com/?re=&str=
But personally, I use RegexBuddy. It costs. But I haven't found anything as robust. And I'm willing to pay for my sanity when regularly confronted by regex like this...
--- Code: Text ---(?imnx) #multiline mode, explicit captures only, with comments^ #start at beginning\s* #optional whitespace( #start optional group ( #begin OR (part|item|exhibit|note) #match from a specific set of words | # OR (?<unknown>\w+) #match any old word ) #end OR \s{1,2} #limited whitespace between each one. capture certain specific ones.)? #end optional group\(? # optional open parenthesis( # begin OR ([\d]{1,2}\w?) # 1-2 numbers with an optional letter on the end | # OR ([ivx]{1,3}) # 1-2 roman numeral letters | # OR ([a-z]) # 1 letters) # end OR\)? # optional end paren\s{0,2} # optional whitespace( # begin OR ([\.](?(unknown)(\s{2,})|(\s+))) # a period followed by at least one space if no unknown header, at least two spaces if unknown header | # OR ([:]\s+) # colon followed by at least one space | # OR (\p{Pd}+) # some number of dashes | # OR (\)\s+) # close paren followed by at leaset one space) # end OR\s* #optional whitespace
At least it's commented... right?
phitsc:
...
At least it's commented... right?
-wraith808 (August 20, 2014, 02:48 PM)
--- End quote ---
On the right, you mean :P
wraith808:
...
At least it's commented... right?
-wraith808 (August 20, 2014, 02:48 PM)
--- End quote ---
On the right, you mean :P
-phitsc (August 20, 2014, 02:52 PM)
--- End quote ---
amirite? :P
Seriously though, it's pretty impressive... though it doesn't seem to recognize global flags as in the beginning of that regex I posted. It also doesn't seem to recognize line comments. But that's a horrendous example... and what it does match, for a web app that costs nothing? Impressive.
Nod5:
Nice find! Let me regexpress my gratitude to phitsc for posting about it.
Navigation
[0] Message Index
Go to full version