<p>I didn't think of huge regexps counting as lots of code before, but yes using <code>URI::MailTo::EMAIL_REGEXP</code> definitely makes a lot more sense here. Thanks for bringing it up, I don't know how I didn't come across it before. (Side Note: Interestingly enough, it actually currently uses the same exact implementation for the <a href="https://github.com/ruby/ruby/blob/master/lib/uri/mailto.rb#L56">expression matching an email</a>).</p>
<p>The problem with using it in a semi-colon delineated approach is that it contains the modifiers <code>\A</code> and <code>\z</code> at the beginning and end respectively, which means it only matches single emails with no trailing whitespace at either end. Building around the regexp using string interpolation directly (i.e using <code>#{URI::MailTo::EMAIL_REGEXP}</code> within the match regex) doesn't work because of this.</p>
<p>I am considering two approaches to dealing with this so semi-colon delineated lists of emails (with possible whitespace around the semicolons) are matched:</p>
<ul>
<li>
<p>My first thought was to manipulate the built-in regexp literal by converting it to a string and using substring indexing so the <code>\A</code> and <code>\z</code> are just not included. The full regex would look like:<br>
<code>\A\s*(?:#{URI::MailTo::EMAIL_REGEXP.to_s[9..-4]})\s*</code> <br>
<code>(;\s*(?:#{URI::MailTo::EMAIL_REGEXP.to_s[9..-4]})\s*)*\z</code>.<br>
This feels very hacky and may not be much easier to read, though.</p>
</li>
<li>
<p>Another possible approach would be splitting the value on ';' first, then stripping each possible email and checking if it matches the built-in regexp directly. In the loop, nil would be returned right away if an unmatched email occurs. The only issue I see with this approach is the fact that it may do some unnecessary work when given a semi-colon delineated list containing an invalid email towards the end, since it iterates through the array created by .split() before checking validity.</p>
</li>
</ul>
<p>Thoughts?</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/2542?email_source=notifications&email_token=AAK2OLMTCADY2VCDXBFZ53DRDULJRA5CNFSM4KWVLMVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMHOYKA#issuecomment-588180520">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLPC6DNJE5QCQQLJPFDRDULJRANCNFSM4KWVLMVA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AAK2OLMZ3GRZRKWEPSDREDLRDULJRA5CNFSM4KWVLMVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMHOYKA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/2542?email_source=notifications\u0026email_token=AAK2OLMTCADY2VCDXBFZ53DRDULJRA5CNFSM4KWVLMVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMHOYKA#issuecomment-588180520",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/2542?email_source=notifications\u0026email_token=AAK2OLMTCADY2VCDXBFZ53DRDULJRA5CNFSM4KWVLMVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMHOYKA#issuecomment-588180520",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>