Reputation: 6544
I am trying to extract the word(s) inside round brackets.
Code:
$('.vote').each(function() {
var vote_count = $('.vote .likedButton').attr('title');
var split_count = vote_count.replace(/\(([^)]+)\)/,"");
alert(split_count);
});
The string I am trying to get-
Message reputation : 50% (2 votes)
trying to get 2 votes
The JavaScript Regex I have above is only deleting this line. Am I missing some regex or do I need to use
.match(/\(([^)]+)\)/);
Can someone explain thank you
Upvotes: 1
Views: 93
Reputation: 205987
$('.vote').each(function() {
var str = $('.likedButton', this).attr('title');
$(this).prepend( str.match(/\(([^)]+)\)/)[1] );
});
Upvotes: 1