I am trying to build a regular expression that matches the numbers with "," and "." as delimiters of thousands and decimals respectively and vice versa.

1. 1,234.56
2. 1.234,56
3. **1234.56**
4. **1234,56**

This regular expression:

```js
/^(\d{1,3}(?:([,\.])\d{3}){1}(?:\2\d{3})*|\d+)(?:(?!\2)[,\.](\d*))?$/

```

matches 1 and 2, but not 3 and 4.

What I try to do is capture the thousands delimiter and prevent it from being used as a decimal delimiter. So, if the delimiter of thousands is "," then the decimal delimiter have to be ".", and if the delimiter of thousands is "." decimal delimiter have to be ",". But then I can't match numbers that don't have thousands delimiter. I think it's because the thousands delimiter catch group is null.

How can the regular expression be constructed to match the four cases?