Hello Regexp Alcolytes!

Disclaimer: Don't point me to Math::Roman, read the node. :-)

Probably the title of this node is horribly wrong, so I try to explain my need in more detail. Let's say you have a set of regexps. Now lets say you are testing each of these regexps against a string to see if it matches or not. Something like this Roman Numeral Thingie. Meanwhile it looks slightly better:

if($str =~ s/XLVIII$/IL/ or $str =~ s/VIII$/IX/ or $str =~ s/III$/IV/ or $str =~ s/DCCCXCIX$/CM/ or $str =~ s/CCCXCIX$/CD/ or $str =~ s/LXXXIX$/XC/ or $str =~ s/XXXIX$/XL/ or $str =~ s/(I{1,2})$/$1I/ or $str =~ s/CDXCIX$/D/ or $str =~ s/CMXCIX$/M/ or $str =~ s/XCIX$/C/ or $str =~ s/I([VXLCDM])$/$1/ or $str =~ s/([VXLCDM])$/$1I/) { } return $str;
And now there is a subroutine to answer the question if a given string actually is a roman numeral:
if($str !~ /[IVXLCDM]+/ || $str =~ /([IXC])\1{3,}/ || $str =~ /([VLD])\1{1,}/ || $str =~ /I[VXLCDM][IVXLCDM]/ || $str =~ /V[XLCDM][VXLCDM]/ || $str =~ /L[CDM][LCDM]/ || $str =~ /X[LCDM][XLCDM]/ || $str =~ /C[DM][CDM]/ || $str =~ /DM[DM]/) { return 0; } return 1;
So lets return to the question. Given a set of regexps and given a wanted logical concatenation (lets start with AND,OR) of these regexps, is there any mechanism to create a smaller, more eficient set of regexps that will have the same effect?

I feel remembered to a similar problem in boolean logic, where you apply some de morgan, do transformations on complex boolean formulae and - sometimes - end up with smaller nifty formulae. Thought same should be possible with regexps.

Thoughts? Answers? Meditation?

Bye
 PetaMem


In reply to A Regexp Assembler/Compiler by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.