Regex arguments and the use of the pipe operator

I’m working on a project with heavy use of the Module “Regex”.
The functions in this module have usually this structure : Regex.function (regex, string).
Therefore the use of the pipe operator is not suitable.

Is there a solution ?

2 Likes

You can write some wrappers for heavily used functions. In wrapper you could reorganize parameter list, for example MyRegex.function(string, regex)

2 Likes

It’s also totally fine to just not use the pipe operator. Sometimes it is over used.

3 Likes

It’s worth noting that you can use

  • String.replace(string, regex, replacement),
  • String.split(string, regex), and
  • String.match?(string, regex)

instead of the equivalent Regex functions.

https://hexdocs.pm/elixir/String.html

4 Likes

Awesome, thank you guys for your answers :slight_smile: !

2 Likes