Depending on the case just confuse who is reading the regex. Parentheses indicate group capture, so in the expression (DE)()([0-9]{1,12})
DE
will be captured in the first group, in the second we will capture nothing and in the third [0-9]{1,12}
, where each group can be referenced by $numerodogrupo
(in fact it depends on the regex engine, some do not use dollar sign), then we have three groups: $ 1, $ 2 and $ 3. Practical example, invert the text DE25324534
using the regex you passed:
var str = 'DE25324534';
var inverted = str.replace(/(DE)()([0-9]{1,12})/, '$3$1$2');
document.write(inverted);
What happens there is that the original string is replaced by $ 3 (the digits) followed by the $ 1 (DE) group, followed by the $ 2 group (there is nothing inside), so you can see that () loose on the regex serves for absolutely nothing in this case , however it may make sense in some situations as shown in the
Guilherme Lautert .