I asked a similar question before and got the correct response. This time though I would rather try and get two variables for the name after the ‘By’ and the ‘Date’ separately.
The problem with the below match is that it isn’t picking up if the name has a space or a dash in it:
<p class="review-rating">
By carolyn.fleetwood
- Feb 11, 2012
-
Something.com
</p>
<p class="review-rating">
By Dont-work
- Feb 11, 2012
-
Something.com
</p>
<p class="review-rating">
By wont work
- Feb 11, 2012
-
Something.com
</p>
$('.review-rating').each(function() {
var matches = $(this).text().match(/\s*By\s+([\w.]+)\s*-\s*([\w, ]+)/);
alert("Date: " + matches[2] + " | By: " + matches[1]);
});
With the above it wont pick up the dash or spaces after the “By “.
See here jfiddle: http://jsfiddle.net/GYSbR/1/
Assuming the rest of the line is their name, just switch from
[\w.]to[^\r\n]+so it catches the rest of the content(s) up until the next new line.