No need to care of whether before/after this digit having other type of words
To just match the pattern of 5 digits number anywhere in the string, no matter it is separated by space or not, use this regular expression (?<!\d)\d{5}(?!\d)
.
Sample JavaScript codes:
var regexp = new RegExp(/(?<!\d)\d{5}(?!\d)/g);
var matches = yourstring.match(regexp);
if (matches && matches.length > 0) {
for (var i = 0, len = matches.length; i < len; i++) {
// ... ydo something with matches[i] ...
}
}
Here's some quick results.
abc12345xyz (?)
12345abcd (?)
abcd12345 (?)
0000aaaa2 (?)
a1234a5 (?)
12345 (?)
<space>
12345<space>
12345 (??)