Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Replacing all the * with ? is not necessarily what you want to do. For example \d* will match 1234567, 123, 1, etc... \d? will only match 1 in the previous example. It will also match nothing. (since the ? means optional)

If you are talking about clarity and maintenance, I would go for the first one because of conciseness. However, I would encourage you to rewrite it. The second one has way too many options and will require a LOT of backtracking if it doesn't match the first time.

While I don't know your exact setup, I can try and help guide you to rewriting this horrible mess of a regex. First, do you need to match multiple square brackets at the beginning? Odds are, you only need one... is it optional? If it's like my prompt, I only have one and it's always there so I could just put a \ infront of it (without the *) if it is optional, you could append it with "?". Now to \w*... can it be nothing? If not, it's probably better to use \w+ (one or more word characters) \@* can you have @@@@@? if not, I'd use \@? What might be better at the beginning would be something like /[\[\w\@\-]+[$\s#\%>~]\]/ Other things to think about are spaces and other characters that may be in the prompt. Also if you are not capturing the prompt, you can try replacing the ASCII escape sequences with // (nothing) before you parse it to help clean it up a bit.

One final note, * isn't "evil" it's just used improperly *a lot*. If you find yourself using it, think... "is there another way I can do this?" Usually there is.


In reply to Re: regex logical equivalence? by MCS
in thread regex logical equivalence? by Anonymous Monk

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.
  • 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 cooling their heels in the Monastery: (3)
    As of 2025-06-21 07:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.