Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the final result. It's a little more robust than my initial effort; it properly escapes sub-expressions, makes sure they appear in the right order and doesn't stop when it finds an empty one: </p> <pre><code>/** * Constructs a regular expression to restore tainted RegExp properties */ function createRegExpRestore () { var lm = RegExp.lastMatch, ret = { input: RegExp.input }, esc = /[.?*+^$[\]\\(){}|-]/g, reg = [], cap = {}; // Create a snapshot of all the 'captured' properties for (var i = 1; i &lt;= 9; i++) cap['$'+i] = RegExp['$'+i]; // Escape any special characters in the lastMatch string lm = lm.replace(esc, '\\$0'); // Now, iterate over the captured snapshot for (var i = 1; i &lt;= 9; i++) { var m = cap['$'+i]; // If it's empty, add an empty capturing group if (!m) lm = '()' + lm; // Else find the escaped string in lm wrap it to capture it else lm = lm.replace(m.replace(esc, '\\$0'), '($0)'); // Push to `reg` and chop `lm` reg.push(lm.slice(0, lm.indexOf('(') + 1)); lm = lm.slice(lm.indexOf('(') + 1); } // Create the property-reconstructing regular expression ret.exp = RegExp(reg.join('') + lm, RegExp.multiline ? 'm' : ''); return ret; } </code></pre> <p>It does what I originally thought to be difficult. This should restore all the properties to their former values, if you use it like so:</p> <pre><code>var // Create a 'restore point' for RegExp old = createRegExpRestore(), // Run your own regular expression test = someOtherRegEx.test(someValue); // Restore the previous values by running the RegExp old.exp.test(old.input); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload