Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You only need to use the <code>new RegExp()</code> part when creating dynamic regular expressions. You can use literals at other times. /\d+/ is the equivalent of <code>new RegExp("\\d+")</code>. Note that you have to escape special characters when using the latter.</p> <p>Also noteworthy is that <code>String#match</code> returns null or an array. This is not apparent based on the supplied solutions (<code>parseInt(name.match(/\d+/), 10)</code>). It just so happens that it is converted to a string when passed to <code>parseInt</code>. <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt" rel="noreferrer">ParseInt</a> converts string values to integers (when possible).</p> <pre><code>name.match(/\d+/)[0] /\d+/.exec(name)[0] </code></pre> <p>Those two are functionally identical in this case.</p> <p>The other match you were referring to (the negative matching) requires a special flag. To duplicate the functionality of gsub you need to tell the regex to be applied more than once with the <code>g</code> flag.</p> <pre><code>'users[107][teacher_type]'.replace(/users\[|\]\[teacher_type\]/g,'') </code></pre> <p>Or if you had to use <code>new RegExp</code> for some reason you'd accomplish the same as above like so:</p> <p>'users[107][teacher_type]'.replace(new RegExp('users\[|\]\[teacher_type\]', 'g'),'')</p> <p>Notice again how I had to escape all the backslashes. Mozilla's Developer Center is a good <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp" rel="noreferrer">reference</a> to familiarize yourself with regex in javascript.</p>
    singulars
    1. This table or related slice is empty.
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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