[ANN] regexp 0.11 (useful for debugging big regexps)

  • Thread starter Simon Strandgaard
  • Start date
S

Simon Strandgaard

Debugging regular expressions becomes easier with this package.

Here is a few examples of how to debug regexp's:

bash-2.05b$ irb
irb(main):001:0> require 'regexp'
=> true
irb(main):002:0> puts /a.{2,4}c/.tree
+-Sequence
+-Inside set="a"
+-Repeat greedy{2,4}
| +-Outside set=U-000A
+-Inside set="c"
=> nil
irb(main):003:0> puts /[^0-9]/.tree
+-Outside set="0".."9"
=> nil
irb(main):004:0> puts /\w+@\w+\.((com)|(net)|(org))/.tree
+-Sequence
+-Repeat greedy{1,-1}
| +-Inside set=["0".."9", "a".."z", "A".."Z", "_"]
+-Inside set="@"
+-Repeat greedy{1,-1}
| +-Inside set=["0".."9", "a".."z", "A".."Z", "_"]
+-Inside set="."
+-Group capture=1
+-Alternation
+-Group capture=2
| +-Sequence
| +-Inside set="c"
| +-Inside set="o"
| +-Inside set="m"
+-Group capture=3
| +-Sequence
| +-Inside set="n"
| +-Inside set="e"
| +-Inside set="t"
+-Group capture=4
+-Sequence
+-Inside set="o"
+-Inside set="r"
+-Inside set="g"
=> nil
irb(main):005:0>


So how do you install this wonderful program...
The recommended way is via RPA..

download-rpa:
http://rubyforge.org/frs/?group_id=265&release_id=760


rpa update
rpa install rpa-base
rpa install re


sidenode: actually this package is a fullblown regexp engine.. but thats
another story.
 
A

Ara.T.Howard

Debugging regular expressions becomes easier with this package.

Here is a few examples of how to debug regexp's:

bash-2.05b$ irb
irb(main):001:0> require 'regexp'
=> true
irb(main):002:0> puts /a.{2,4}c/.tree
+-Sequence
+-Inside set="a"
+-Repeat greedy{2,4}
| +-Outside set=U-000A
+-Inside set="c"
=> nil
irb(main):003:0> puts /[^0-9]/.tree
+-Outside set="0".."9"
=> nil
irb(main):004:0> puts /\w+@\w+\.((com)|(net)|(org))/.tree
+-Sequence
+-Repeat greedy{1,-1}
| +-Inside set=["0".."9", "a".."z", "A".."Z", "_"]
+-Inside set="@"
+-Repeat greedy{1,-1}
| +-Inside set=["0".."9", "a".."z", "A".."Z", "_"]
+-Inside set="."
+-Group capture=1
+-Alternation
+-Group capture=2
| +-Sequence
| +-Inside set="c"
| +-Inside set="o"
| +-Inside set="m"
+-Group capture=3
| +-Sequence
| +-Inside set="n"
| +-Inside set="e"
| +-Inside set="t"
+-Group capture=4
+-Sequence
+-Inside set="o"
+-Inside set="r"
+-Inside set="g"
=> nil
irb(main):005:0>


wow - that is very cool simon! i can't remember is this dfa or nfa re?

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| A flower falls, even though we love it;
| and a weed grows, even though we do not love it.
| --Dogen
===============================================================================
 
S

Simon Strandgaard

Debugging regular expressions becomes easier with this package.
[snip]

wow - that is very cool simon! i can't remember is this dfa or nfa re?

Its nfa, still without optimizations.. but good for debugging big regexps :)

When (if) I get enough spare time I will make a perl6 parser for it.
Later I hopefully can optimize it..


This morning I got this idea to use my debugging parse tree with Ruby's Regexp
class.. I wrote the necessary 3 lines of code.. and had something useful to
many people. I must be insanely dumb not to realizing this ages ago.

I hope you can use it. You may want to add it to your dot-irb file.

As always im interested in feedback and is open to suggestions/patches.
I am working many project and is very busy with my study+job at the moment..
so best way to help is by submitting patches ;-)

Thanks to those who try this package.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top