I got problems with this regex. I want to return the first occurrence of this pattern #2344..... But somehow it is returning all occurrences.
var title = '#34 #24 pofejwopwefjopewfjpfeijefow'
pointsRegEx = /(#\d+){1}/;
points = title.match(pointsRegEx);
JSFIDDLE: http://jsfiddle.net/KbGVU/1
Your regex is working fine. In your regex, you have
(). This creates a group..matchreturns an array. The 1st element is the result matched by the entire regex, the other elements are each group from your regex..matchis returning you['#34','#34']because the 1st is the entire regex, and the 2nd is the group in your regex(#\d+).Note:
{1}is not needed, as it will match 1 match by default.The properties of the array returned from
.matchis documented here: mozilla docs.