[erlang-questions] String Pattern Matching

Steve Vinoski vinoski@REDACTED
Sun Sep 7 20:13:35 CEST 2008


On 9/7/08, Luke Galea <galeal@REDACTED> wrote:
> Hi all,
>
>  I get the sense that most erlangers feel that regular expressions
>  aren't needed and that pattern matching can do the job.

Not exactly.

>  But I am absolutely killing myself trying to port Ruby's
>  ActiveSupport Inflector over to erlang. It lets you pluralize and
>  singularize strings based on a set of rules.
>
>  For instance:
>         ([m|l])ouse$ -> $1ice
>  or
>         ([^aeiouy]|qu)y$ -> $1ies

With R12B-4:

Eshell V5.6.4  (abort with ^G)
1> {ok, Re1} = re:compile("([m|l])ouse$"),
1> re:replace("mouse", Re1, "\\1ice", [{return, list}]).
"mice"
2> {ok, Re2} = re:compile("([^aeiouy]|qu)y$"),
2> re:replace("body", Re2, "\\1ies", [{return, list}]).
"bodies"

--steve



More information about the erlang-questions mailing list