For the html below, I am trying to put a variable to just “oakbarrels” and a variable to just “Dec 25, 2011”. I have already been able to get the “Dec 25, 2011” with regex but I cannot figure out how to get the rest. Basically I want to remove “By ” and everything after the first ” -“:
<p class="review-rating">
By oakbarrels
- Dec 25, 2011
-
Something.com
</p>
<script>
var thedate = $('.review-rating').text().match(/\-\s([^\n]+)/)[1].trim();
var from = ???
</script>
jsFiddle.
matches[1]will contain'oakbarrels'andmatches[2]will contain'Dec 25, 2011', as per your example.I also changed your
html()totext(). It doesn’t appear the HTML is relevant to matching the text.