lass="example"> <pre class="codepre"><code class="code">(* A simple implementation of Js.String.startsWith *)

let str = "hello world!"

let startsWith substring target =
  Js.Re.fromString ("^" ^ substring)
    |&gt; Js.Re.test target

let () = Js.log (str |&gt; startsWith "hello") (* prints "true" *)
</code></pre>  </pre>
                    </div>
                    </div>

                  </body></html>