Website message overhaul, pass 2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Nov 20 11:59:51 PST 2011


On 11/20/11 8:17 AM, Peter Alexander wrote:
> How about this one:
>
> // Match email addresses on each line of standard input
> // using a compile-time generated regular expression engine.
> import std.stdio, std.regex;
>
> void main() {
> string email = r"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b";
>
> foreach (line; stdin.byLine()) {
> foreach (m; match(line, regex(email, "i"))) {
> writefln("%s[%s]%s", m.pre, m.hit, m.post);
> }
> }
> }
>
> Demonstrates:
> - Syntax
> - Imports
> - Raw string literals
> - Foreach with type deduction
> - CTFE with regex
> - "Batteries included" library (std.byLine(), regex, match, writefln)
> - General succinctness of D code

Great. Save that for the contest.

Andrei


More information about the Digitalmars-d mailing list