Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active January 1, 2019 01:25
Show Gist options
  • Select an option

  • Save rauschma/cd8e51f512d374a9f3a3dfe4906c23b2 to your computer and use it in GitHub Desktop.

Select an option

Save rauschma/cd8e51f512d374a9f3a3dfe4906c23b2 to your computer and use it in GitHub Desktop.

Revisions

  1. rauschma revised this gist Dec 31, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions regexp-flags.js
    Original file line number Diff line number Diff line change
    @@ -14,3 +14,6 @@ const cloneFlags = regExp.flags.includes('g')
    // Solution 3
    const f = regExp.flags;
    const cloneFlags = f.includes('g') ? f : f+'g';

    // Solution 4
    const cloneFlags = [...new Set(regExp.flags + 'g')].join('');
  2. rauschma created this gist Dec 31, 2018.
    16 changes: 16 additions & 0 deletions regexp-flags.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // Add flag 'g' if it isn’t there, yet

    // Solution 1
    let cloneFlags = regExp.flags;
    if (!cloneFlags.includes('g')) {
    cloneFlags += 'g';
    }

    // Solution 2
    const cloneFlags = regExp.flags.includes('g')
    ? regExp.flags
    : regExp.flags + 'g';

    // Solution 3
    const f = regExp.flags;
    const cloneFlags = f.includes('g') ? f : f+'g';