compile-time regex redux
Walter Bright
newshound at digitalmars.com
Wed Feb 7 00:51:25 PST 2007
Andrei Alexandrescu (See Website For Email) wrote:
> Walter Bright wrote:
>> But I think we now have good reasons to revisit this, at least for
>> compile time use only. For example:
>>
>> ("aa|b" ~~ "ababb") would evaluate to "ab"
>>
>> I expect one would generally only see this kind of thing inside
>> templates, not user code.
>
> The more traditional way is to mention the string first and pattern
> second, so:
>
> ("ababb" ~~ "aa|b") // match this guy against this pattern
>
> And I think it returns "b" - juxtaposition has a higher priority than
> "|", so your pattern is "either two a's or one b". :o)
My bad. Some more things to think about:
1) Returning the left match, the match, the right match?
2) Returning values of parenthesized expressions?
3) Some sort of sed-like replacement syntax?
An alternative is to have the compiler recognize std.Regexp names as
being built-in.
More information about the Digitalmars-d
mailing list