[erlang-questions] regular expressions (again :)

Gaspar Chilingarov <>
Wed Dec 13 10:56:05 CET 2006

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 	

_(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 =/=

_(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.

Gaspar Chilingarov

System Administrator,
Network security consulting

t +37493 419763 (mob)
i 63174784

More information about the erlang-questions mailing list