 <p>Regexes are specific literals in JavaScript, they are not created as strings. Simply remove the single quotes:</p> <pre><code>$(this).attr('src').replace(/-[\d]+x[\d]+/, '') </code></pre> <p>Note that <code>replace</code> does not work in-place but returns the resultant string instead. So depending on whether you want to process it further or just write it back into the attribute, you will have to assign this to something.</p>