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