Hail all ye Monkley monks,

I'm sure that this is a pretty straightforward question, but I've really only just started to get my feet wet with Regexp's and I'm fresh out of ideas.

I'm writing a script to release a number of emails from Quarantine. Essentially, the user is provided with a list of messages to release. I am trying to allow the user to enter a range of options, for example: 1,4-6,a. "1" would be release the first message, 4-6 would be messages "4-6" and "a" would release all messages. I am trying to write a regular expression that will eveluate a string of any length (i.e. with an infinite potential for message numbers) and ensures that it is in a valid format. Currently I am using the following peice of code which will only check if the first peice of data entered matches any of the expression given:

use strict; my $releasing; while ($releasing !~ /[0-9][0-9]?,?|[aA],?|[0-9][0-9]?\-[0-9][0-9]?,?/ +) { print ("\n\nPlease type the numbers of the messages that are to be + released (n-n and n \nare allowable, A for all): "); $releasing = <STDIN>; chomp $releasing; }
I know that I could just accept the data, split it by comma and then evaluate each section, but I'd like to be able to continue prompting for the message selection then and there if the data entered is incorrect. For the record, I have tried using /^[0-9][0-9]?,?$|^[aA],?$|^[0-9][0-9]?\-[0-9][0-9]?,?$/ but that didn't help much either (only allowing one item entry). I have a feeling that I should be using /g and \G, but I can't really find a decent resource on the 'net to give me a good start at this.


Thanks

In reply to Regular Expression Question by SquireJames

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.