From 7a6428325e3fdadc3dcd43f14e3e965712a049f4 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 19:45:47 +0200 Subject: [PATCH] Added cloneRegExp --- snippets/cloneRegExp.md | 14 ++++++++++++++ tag_database | 1 + 2 files changed, 15 insertions(+) create mode 100644 snippets/cloneRegExp.md diff --git a/snippets/cloneRegExp.md b/snippets/cloneRegExp.md new file mode 100644 index 000000000..f6722ea3d --- /dev/null +++ b/snippets/cloneRegExp.md @@ -0,0 +1,14 @@ +### cloneRegExp + +Clones a regular expression. + +Use `new RegExp()`, `RegExp.source` and `RegExp.flags` to clone the given regular expression. + +```js +const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags); +``` + +```js +const regExp = /lorem ipsum/gi; +const regExp2 = cloneRegExp(regExp); // /lorem ipsum/gi +``` diff --git a/tag_database b/tag_database index 7b9178af1..ab974eb2e 100644 --- a/tag_database +++ b/tag_database @@ -10,6 +10,7 @@ chainAsync:function chunk:array clampNumber:math cleanObj:object +cloneRegExp:utility coalesce:utility coalesceFactory:utility collatz:math