title: How can I match a repeating pattern within a repeating pattern without specifying the alternatives twice?
body: <p>Suppose I have the following string, representing one or many days or day ranges:</p>
  <pre><code>mon,thu..fri,sun
  </code></pre>
  <p>How can I match any arbitrary list of ranges or single days with a regular expression, <strong>without expanding the day alternatives twice</strong>?</p>
  <p>I currently have this:</p>
  <pre><code>(?P&lt;weekdays&gt;
      (                        
          \b
          (mon|tue|wed|thu|fri|sat|sun)
          (\.\.(mon|tue|wed|thu|fri|sat|sun))?
          ,?
      )*
  )
  </code></pre>
  <p>... this works, but it forces me to repeat the day alternatives in the regex (which are simplified here but are longer!). Note that this regex matches for <code>fri,sat,</code> thus optionally ending in a comma, this IS the desired behavior.</p>
  <p>I also tried making the range portion a limited repetition using <code>{1,2}</code>, but I am unable to avoid matching the invalid <code>mon..tue..fri</code> because the pattern restarts via the optional comma.</p>
  <p>Note that this is part of a longer regex so I can't use the global flag.</p>
  <p><a href="https://regex101.com/r/8V2FG6/5" rel="nofollow noreferrer">This is the Regex101 URL</a>, where I also added some unit tests.</p>
  <p><strong>Small edit:</strong> used the \b metacharacter instead of a negative lookahead.</p>