'REGEX remove spaces or dashes, if they are in between numbers

I'm in the process of modifying an existing regex to match Credit Card numbers. Sometimes such numbers are presented as follows that separate the number chunks with spaces or dashes as follows;

3756-4564-2323-3435
3756 6432 3233 435

These types of matches should be preprocessed to remove those special characters. Usually the number chunks are of 3 to 4 digits.

thanks



Solution 1:[1]

In bash you could remove anything that is not numbers with:

$ var="3756-4564-2323-3435"
$ echo "${var//[^0-9]}"
3756456423233435

Sources

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

Source: Stack Overflow

Solution Source
Solution 1