Because /g is just the repetition of the regex, and it may not be possible in some circumstances, I think

It could be perfectly feasible to have a regex like:

/^\w+\s+(?:(\d+)\s+){3}\w+$/

So I want a word, 3 group of digits and a word. But right now I don't know how to get the 3 values for the group of numbers. So I usually do something like:

/^\w+\s+(\d+)\s+(\d+)\s+(\d+)\s+\w+$/

that doesn't look so good. In extreme cases n can be far bigger than 3 and I should get the whole string of numbers and then split them. Also, if I want instead of just n repetitions to force a threshold ({3,10} for example) then I'm at a loss and I have to implement it in two steps.

I know that may be even clearer than the regex I'm trying to write, but I'm just curious about it. I'd like my regex to fit as as much as possible the format of my input and get the values straightforwardly. Don't know if it can be done though. That's my question.

There's no real problem behind, nor real output either. It's just something I've found several times and I've never been happy with the solutions I've implemented.

Hope it makes more sense now,

Thanks


In reply to Re^4: Variable matching on a regex by LaintalAy
in thread Variable matching on a regex by LaintalAy

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.