[erlang-questions] regular expressions (again :)

Bob Ippolito bob@REDACTED
Wed Dec 13 11:33:06 CET 2006


On 12/13/06, Gaspar Chilingarov <nm@REDACTED> wrote:
> Hi there!
>
> I found a lot of discussions on mailing list about regexps,
> but found no really usable solution.
>
> Calling regexp:match or similar functions is too ugly.
>
> what about following syntax ? which can be converted to existing
> functions using parse transform  (or another RE engine if necessary).
>
>
>
> String = "http://localhost/script?arg&arg2",
>
> _( TextVariable = RE) should check that pattern matches, so
> _(String == "https://") will produce false
> _(String == "http://(.*)/(.*)$") will produce
>      tuple {"localhost", "script?arg&arg2"} -- i.e. tuple with matched
>      elements
>
> _(TextVariable =:= RE) should do the same thing as perl m/re/g - i.e.
> return all matches.
> _(String =:= "([?&]arg.*)") will return [ {"?arg"}, {"&arg2"} ]
>   in case if matching failed false should be returned.
>
> and the last one is substitution - I suggest to use /= and =/=
> so
>
> _(String /= RE) will replace only one (first) match
> _(String =/= RE) will replace all matches in the string.
>
>
> _() construct is used, because I found no other short constructs, which
> parse correctly to erlang terms. Are there any ideas?
>
> Writing something like re:r(String == "http://(.*)/(.*)$") is also
> possible, but requires more typing.

regexes aren't (or at least shouldn't be) common enough to warrant a
single character shortcut like that...

Besides, _(expr) almost universally means gettext.

-bob



More information about the erlang-questions mailing list