Is there a way for me to format a string based on a regEx pattern. That is can I have a string and apply that pattern. A perfect example would be a phone number or credit card. For instance if I had this function:
public String formatNumber(String input, String patter) {
// What to do...
}
I would like to describe the pattern in a single string rather than do multiple string operations to get the input into the desired format.
Not that the input might not be the entire input but only part of the input and it still needs formatted.
EXAMPLE:
-------
Pattern = "\(\d{3}\) \d{3}-\d{4}"
123456 => (123) 456
1234567 => (123) 456-7
1234567890 => (123) 456-7890
12 => (12