I would like to get all the numbers composed of 4 digits. Before and after there should be 2 non digit characters or no characters at all.
This is what I have so far. In this example the correct result would be only "0000" but it also matches 1234, 4567, 5678.
What am I missing ?
Js fiddle: http://jsfiddle.net/M8FYm/3/
Source:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<title>Regex test</title>
<script type="text/javascript">
$(document).ready(function(){
pattern = '(\D{2})?('+'([0-9]{4})'+')(\D{2})?';
var regexp = new RegExp(pattern, "g");
var string = $('.test').html();
while (match = regexp.exec(string)) {
console.log(match);
}
})
</script>
</head>
<body>
<p class="test">
1234 4567 67
0000 345
456 23 0000
12345678
</p>
</body>
</html>