On Fri, Nov 6, 2015 at 1:20 PM, Brian Terlson
<[email protected]> wrote:
> RegExp.re or similar seems nice:
>
> ```
> let re = RegExp.re("x")`
>     (\d{3}-)? # area code (optional)
>     \d{3}-    # prefix
>     \d{4}     # line number
> `;
> ```
>
> But it seems like previous proposals of this want escaping which doesn't seem 
> ideal for this purpose. Do we need both `RegExp.re` and `RegExp.escapedRe`?

Escaping happens if you use interpolation into the string template:
```
let re = RegExp.re`(?x:
    (\d{3}-)?      # area code (optional)
    ${ /\d{3}/ }-  # prefix
    \d{4}           # line number
    ( ${ "*" } \d+ )?  # extension
)`;
```
If the interpolated expression is a regexp, then things seem
relatively straightforward (although there are corner cases to
consider).  If the interpolated expression is a string, then it is
suggested that you use some sort of automatic escaping.
 --scott
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to