Is there a way of combining these two patterns? I would like to remove spaces and non-alphanumeric characters.
This does work, it just seems inefficient repeating the replace
function.
var str;
str = $('p').text().replace(/[^a-zA-Z 0-9]+/g, '');
str = str.replace(/\s/g, '');
alert(str);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>What's Happening Here!</p>
Example jsFiddle.