'Regex different hashes

so I'm struggling with regex. I'll start with what I want to achieve and then proceed to what I have "so far".

So for example I have commit name lines

merge(#2137): done something
Merge pull request #420 from Example/branch
feat(): done something [#2137JDN]
merge(#690): feat(): done something [#2137JDN]

And I want to grep only by PR ID, or if it's not there then it'd search by that second hash

#2137
#420
#2137JDN
#690

For now I have this regex, but it's not perfect

/(\(|\s|\[)(#\d+|#.+)(\)|\s|\])/g

because it's capturing this

(#2137)
\s#420\s
[#2137JDN]
(#690)[#2137JDN]

How I can improve it to get what I want exactly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source