Yes, maybe it works, but I can't comment much on it without having seen the data, which you haven't shown yet.

One thing, though: if you need an atom or a sub-pattern once and only once, then you don't need a quantifier such as {1}, that's what the regex engine will do anyway by default. So that this slightly simpler substitution should do the same thing:

$loop_variable =~ s/ ?[A-Za-z] (\[(.*)\])? ?\d+(.*)?\.+(.*)?//g;
I believe the rest of the regex could probably be improved. For example something like .* is rarely a good idea (.*? is often better), and (\[(.*)\])? is probably better written as (\[(.*?)\])? or as (\[[^]]*\])? (untested). That's just one example.

But I would need to see the data and to know what exactly you find significant in the strings you are trying to match (what are the invariants that you are looking for and what are the variable parts) before I could really give more informed advice.


In reply to Re^3: String replacement by Laurent_R
in thread String replacement by kepler

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.