Regex arguments and the use of the pipe operator


#1

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

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


#3

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


#4

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


#5

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