<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Not speaking to any FreeRADIUS issues but just to the regular expression, you typically need to escape the period, dash, and other special characters within the pattern if you are looking to match them. For example<div><br></div><div>^email:([a-z0-9\._\-]+@[a-z0-9\.\-]+\.[a-z]{2,4})</div><div><br></div><div>There are a number of regex test tools on the web as well as tools you can download and install. I would suggest that you start with those and make sure the pattern is working first and then try to implement it in FreeRADIUS.</div><div><br></div><div>Jim Lohiser</div><div>Imagine Net, inc.</div><div><br><div><br><div><div>On Oct 23, 2013, at 4:36 PM, Franks Andy (RLZ) IT Systems Engineer <<a href="mailto:Andy.Franks@sath.nhs.uk">Andy.Franks@sath.nhs.uk</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="MS Exchange Server version 6.5.7638.1">
<title>Regex question</title>
<div>
<!-- Converted from text/rtf format --><p dir="LTR"><span lang="en-gb"><font face="Calibri">Hi All,</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> Got a regex thing I can</font></span><span lang="en-gb"><font face="Calibri">’t explain, but it may of course be down to my inexperience with regexs generally. Please forgive the non</font></span><span lang="en-gb"><font face="Calibri">-</font></span><span lang="en-gb"><font face="Calibri">ideal email address</font></span><span lang="en-gb"><font face="Calibri"> regex</font></span><span lang="en-gb"><font face="Calibri">, it’s not great, but not really my focus here at this point</font></span><span lang="en-gb"><font face="Calibri">, I aim to improve it.</font></span><span lang="en-gb"><font face="Calibri"> For now it’s as simple as I can make it, having paired it down to hopefully find the problem.</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">We’re using a captive portal which only allows pass-through of a username and password as user “fields”. The system uses voucher auth, so we don</font></span><span lang="en-gb"><font face="Calibri">’t actually use the password field for a password, rather using it to capture email address, browser agent, version and OS details from the client’s browser.</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">This is a via the user-password string in the format</font></span><span lang="en-gb"> <font face="Calibri">field:<string> field2:<string></font></span><span lang="en-gb"> <font face="Calibri"> - fields, with the string following a colon, separated by spaces.</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">e.g.</font></span><span lang="en-gb"> </span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">em</font></span><span lang="en-gb"><font face="Calibri">ai</font></span><span lang="en-gb"><font face="Calibri">l:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">The string is passed through a few regexes, each picking off the field string in a</font></span><span lang="en-gb"> <font face="Calibri">capture</font></span><span lang="en-gb"><font face="Calibri"></font></span><span lang="en-gb"> <font face="Calibri">group. It’s failing on the first, the email regex being</font></span><span lang="en-gb"><font face="Calibri"> pretty simple</font></span><span lang="en-gb"><font face="Calibri">:</font></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">^email:([a-z0-9._-]</font></span><span lang="en-gb"></span><a href="mailto:+@[a-z0-9.-]+/.[a-z]{2,4}"><span lang="en-gb"><u><font color="#0000FF" face="Calibri">+@[a-z0-9.-]+\.[a-z]{2,4}</font></u></span><span lang="en-gb"></span></a><span lang="en-gb"><font face="Calibri">)</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">I’ve tried various delimiters</font></span><span lang="en-gb"> <font face="Calibri"> but all result in the same issue:</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">em</font></span><span lang="en-gb"><font face="Calibri">ai</font></span><span lang="en-gb"><font face="Calibri">l:my.email@<a href="http://address.com">address.com</a></font></span><span lang="en-gb"><font face="Calibri">,</font></span><span lang="en-gb"><font face="Calibri">browseragent:safari</font></span><span lang="en-gb"><font face="Calibri">,</font></span><span lang="en-gb"><font face="Calibri">version:7</font></span><span lang="en-gb"><font face="Calibri">,</font></span><span lang="en-gb"><font face="Calibri">os:ios5</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">em</font></span><span lang="en-gb"><font face="Calibri">ai</font></span><span lang="en-gb"><font face="Calibri">l:my.email@<a href="http://address.com">address.com</a></font></span><span lang="en-gb"><font face="Calibri">#</font></span><span lang="en-gb"><font face="Calibri">browseragent:safari</font></span><span lang="en-gb"><font face="Calibri">#</font></span><span lang="en-gb"><font face="Calibri">version:7</font></span><span lang="en-gb"><font face="Calibri">#</font></span><span lang="en-gb"><font face="Calibri">os:ios5</font></span><span lang="en-gb"></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">I’ve also tried compiling with and without libpcre3-dev, same</font></span><span lang="en-gb"><font face="Calibri"> -</font></span><span lang="en-gb"><font face="Calibri"> the regex is not stopping at the space or , or #, whatever delimiter I choose.</font></span><span lang="en-gb"><font face="Calibri"> The non email regexes seem to work ok..</font></span><span lang="en-gb"></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">Code :</font></span><span lang="en-gb"><font face="Calibri"> (in policy.d folder)</font></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">e</font></span><span lang="en-gb"><font face="Calibri">mail_regexp=</font></span><span lang="en-gb"><font face="Calibri"> "^email:([a-z0-9._-]+@[a-z0-9.-]+\\.[a-z]{2,4})"</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> if ("%{User-Password}" =~ /${policy.email_regexp}/){</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> Email-Address := "%{1}"</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> }</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">}</font></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">Result:</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> ? if ("%{User-Password}" =~ /^email:([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,4})/)</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{User-Password}" -> 'email:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /^email:([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,4})/) -> TRUE</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) if ("%{User-Password}" =~ /^email:([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,4})/) {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{1}" -> '<a href="mailto:my.email@address.com">my.email@address.com</a> brow'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) Email-Address := "<a href="mailto:my.email@address.com">my.email@address.com</a> brow"</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # update control = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) [noop] = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # if ("%{User-Password}" =~ /^email:([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,4})/) = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ... skipping else for request 0: Preceding "if" was taken</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # check_email_address check_email_address = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) check_browser_agent check_browser_agent {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /browseragent:([a-z0-9_-]+)/)</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{User-Password}" -> 'email:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /browseragent:([a-z0-9_-]+)/) -> TRUE</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) if ("%{User-Password}" =~ /browseragent:([a-z0-9_-]+)/) {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{1}" -> 'safari'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) Browser-Agent := "safari"</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # update control = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # if ("%{User-Password}" =~ /browseragent:([a-z0-9_-]+)/) = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # check_browser_agent check_browser_agent = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) check_browser_version check_browser_version {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /version:([a-z0-9_-]+)/)</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{User-Password}" -> 'email:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /version:([a-z0-9_-]+)/) -> TRUE</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) if ("%{User-Password}" =~ /version:([a-z0-9_-]+)/) {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{1}" -> '7'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) Browser-Version := "7"</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # update control = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # if ("%{User-Password}" =~ /version:([a-z0-9_-]+)/) = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) } # check_browser_version check_browser_version = noop</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) check_browser_os check_browser_os {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /os:([a-z0-9_-]+)$/)</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{User-Password}" -> 'email:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) ? if ("%{User-Password}" =~ /os:([a-z0-9_-]+)$/) -> TRUE</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) if ("%{User-Password}" =~ /os:([a-z0-9_-]+)$/) {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) expand: "%{1}" -> 'ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(0) Browser-OS := "ios5"</font></span><span lang="en-gb"></span></p><div><span lang="en-gb"></span><br class="webkit-block-placeholder"></div><p dir="LTR"><span lang="en-gb"><font face="Calibri">I also tried a different regex, but the problems seem worse there..</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri"> ? if ("%{User-Password}" =~ /^email:([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)*(\.[a-z]{2,4}))/)</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) expand: "%{User-Password}" -> 'email:my.email@<a href="http://address.com">address.com</a> browseragent:safari version:7 os:ios5'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) ? if ("%{User-Password}" =~ /^email:([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)*(\.[a-z]{2,4}))/) -> TRUE</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) if ("%{User-Password}" =~ /^email:([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)*(\.[a-z]{2,4}))/) {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) update control {</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) expand: "%{1}" -> '<a href="mailto:my.email@address.com">my.email@address.com</a> browseragent:safari version:7 os:ios'</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) Email-Address := "<a href="mailto:my.email@address.com">my.email@address.com</a> browseragent:safari version:7 os:ios"</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">(1) } # update control = noop</font></span><span lang="en-gb"></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">Any ideas what I’m doing wrong?</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">Thanks</font></span></p><p dir="LTR"><span lang="en-gb"><font face="Calibri">andy</font></span><span lang="en-gb"></span></p>
</div>
-<br>List info/subscribe/unsubscribe? See <a href="http://www.freeradius.org/list/users.html">http://www.freeradius.org/list/users.html</a></blockquote></div><br></div></div></body></html>