I want to much Redmine issue numbers in Version Control commit messages, which are numbers preceded by a # sign, eg #123, #456 etc, but I only want to match them if they are surrounded by a punctuation character set, or are the beginning or end of the line. eg ‘#234aa, #567’ should match only #567. ‘, – ;#456,,’ should match #456 because ‘,-; ‘ are all in the punctuation character set.
I have tried an example expression
function myFunction()
{
var str="erwet,#3456 #623 #345 fdsfsd";
var n=str.match(/\#[\d+]+[\s]/g);
document.getElementById("demo").innerHTML=n;
}
I also want to match them into an array or a list, but the demo I am trying matches them into a single string.
Okay, so I think I have a regex that does the job, the fact that it’s matching punctuation made a couple of sentences in your example a little confusing but here goes:
Which can be broken down as:
So we get:
I’m not so sure about the
\sin the last bit, because that’s neither punctuation nor end of line, but you had it in your base code so I assume it’s something you want.