why it stops after a word with a trailing ','

(\w+[.,;\s]?)+ means to match one or more word characters, followed by zero or one [.,;\s] character, and the outer (...)+ means that the next thing must be one or more word characters, and so on. However, in the string "Orinda, which", the , character isn't followed by a word character, it's a space. So it isn't really the difference between comma and space that's causing it to stop, it's more than one non-word character (Update: more precisely, a [.,;\s] character followed by a non-word character) - e.g. .. or ;- have the same effect.

I need to understand how to stop it at that first comma, (it stops when it should not) as well as how to let it run on to some other anchor.

If you wanted to stop it at the first comma, then you could remove the comma from the [.,;\s] group. A common way to say "match until some character", using the example of ;, is [^;]*; - this assumes that those characters can't be escaped.

One test case isn't really enough though, see Re: How to ask better questions using Test::More and sample data.

Update 2: Minor edits for clarity.


In reply to Re: Regex capture group with + repeat by haukex
in thread Regex capture group with + repeat by perlboy_emeritus

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.