Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
The reason why
$command =~ m/(!\w+\s?.+?)(?=!\w)/simg;
only returns one result is because you call it in scalar or void context, once. You either have to loop through the parts, or extract them all at once and then loop through each.

The latter approach look easier to me. It can be done by modifying your code like:

my @commands = $command =~ m/(!\w+\s?.+?)(?=!\w)/simg;
Except that you'll miss the last command because there's no "!word" pattern following it. You can fix that by allowing that it's followed by either a new command, or the end of the string.
my @commands = $command =~ m/(!\w+\s?.+?)(?=!\w|\z)/simg;
n.b. The flags /i and /m are superfluous, and 1) there's nothing case sensitive and 2) there are no "^" or "$" meta characters that can change meaning.

Anyway, once you have the list of commands, you can go through them like

foreach my $command (@commands) { ... }
and process them pretty much as you do now; reusing the $command variable name (it's a different variable, regardless) allows to keep the remainder of the code as is.

In reply to Re: Splitting multiple commands with regex failure by bart
in thread Splitting multiple commands with regex failure by CalebH

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (10)
    As of 2014-10-30 23:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (211 votes), past polls