Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found