Docs / BuckleScript / RegularExpression

Regular Expressions

On the native side, you might have seen Str in the standard library, or ocaml-re. Although these are viable choices on native, on the BuckleScript side, you should use Js.Re, which compile to straightforward JavaScript regular expressions. Advantages:

  • Better unicode support

  • No library overhead

  • No extra compilation output (it's all externals that get compiled away)

  • Same performance characteristics than JS regex, since it basically compiles to it

Creation

We have a shorthand for creating the regex:

RE
let f = [%bs.re "/b/g"]

Output:

JS
var f = /b/g