You can use regex:
> re:run("foobarbaz", "bar", [{capture, first, list}]). {match,["bar"]}
See the documentation for re: run / 3 for more information. In particular, you may find that another capture option is right for you.
Or, if you do not need all the functions of regular expressions, string: str / 2 might be enough:
> string:str(" Hello Hello World World ", "Hello World"). 8
source share