Chapter 12 Example 10
♥0 |
Line 17 |
Modified 2009-07-23 06:49:04 |
MIT License
archived:2017-03-30 03:25:25
ActionScript3 source code
/**
* Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/cJ63
*/
package {
import com.actionscriptbible.Example;
public class ch12ex10 extends Example {
public function ch12ex10() {
var testLink:String = '"Roger Braunstein" <roger@actionscriptbible.com>';
trace(headerToLink((testLink)));
//<a href="mailto:roger@actionscriptbible.com">Roger Braunstein</a>
}
protected function headerToLink(fromField:String):String {
//a from address with a name takes the format:
//(some stuff, perhaps in quotes, which is the name),
//perhaps some whitespace, <,
//(some stuff with an @, which is the address), >
var findHeader:RegExp = /"? (?P<name>.+?) "? \s* < (?P<email>.+@.+) >/x;
var match:Object = fromField.match(findHeader);
if (match) {
return '<a href="mailto:' + match.email + '">' + match.name + '</a>';
}
//if this is not the format of the header, don't mess with it
return fromField;
}
}
}