Policy change for regex libraries
mail at justinbogner.com
mail at justinbogner.com
Mon Jan 12 17:46:16 EST 2009
Chris Kuklewicz <haskell at list.mightyreason.com> writes:
> Matching "0123" and replacing all matches with themselves wrapped in
> angle brackets. The policies of 0, 1, and 2 above lead to (computed
> partly by hand):
>
> regex of "[0123]?"
> 0): "<0><1><2><3><>"
> 1): "<0><1><2><3><>"
> 2): "<0><1><2><3>"
>
> regex of "[012]?"
> 0): "<0><1><2>3<>"
> 1): "<0><1><2>3<>"
> 2): "<0><1><2>3<>"
>
> regex of "[013]?"
> 0): "<0><1><>23"
> 1): "<0><1><>2<3><>"
> 2): "<0><1>2<3>"
>
> regex of "[023]?"
> 0): "<0><>123"
> 1): "<0><>1<2><3><>"
> 2): "<0>1<2><3>"
>
> regex of "[123]?"
> 0): "<>0123"
> 1): "<>0<1><2><3><>"
> 2): "<>0<1><2><3>"
>
> regex of "[03]?"
> 0): "<0><>123"
> 1): "<0><>1<>2<3><>"
> 2): "<0>1<>2<3>"
>
> regex of "[03]?"
> 0): "<0><>123"
> 1): "<0><>1<>2<3><>"
> 2): "<0>1<>2<3>"
>
> regex of "[12]?"
> 0): "<>0123"
> 1): "<>0<1><2><>3<>"
> 2): "<>0<1><2>3<>"
>
Policy 2 seems the most intuitive to me, I can't imagine a situation
where you would want the empty match at the end of a non-empty match. On
the other hand, I don't think I've ever used a regular expression that
matched an empty string, so it's not particularly important to me.
More information about the Libraries
mailing list