Removing non-digits from numbers
When completing online forms, you will often copy information from one source (such as a text document or another web page) and paste that into form fields. Unfortunately, some web pages expect certain numbers to be entered without any separators. For example, if you paste the phone number 1-555-444-1234, you get an error. Similarly, credit card numbers are typically written as groups of four digits with spaces between the groups: 1234 3456 5678 7890, but many online forms reject the spaces or even cut off the number after 16 characters, which results in 1234 3456 5678 7.
In Typinator, you can use the built-in /Regex function to automatically remove all non-digits from the text in the clipboard.
In the full form, the /Regex function takes three arguments:
"text" is the input text that should be translated. "original" is a regular expression pattern that describes which text should be replaced, and "replacement" is the text with which the matches should be replaced. In the /Regex function, these parts are separated by slashes, with a double slash separating the original/replacement pair from the text.
To remove all non-digits from the text in the clipboard, we can use the following expansion:
The notation […] describes a set of characters. For example, [abcdef] stands for all lower case letters from a to f. You can also write this with a minus sign as [a-f]. In our example, [0-9] stands for any digit. The caret ^ at the beginning negates the set, so [^0-9] means "any non-digit".
To make the rule more versatile, we have added \n and \r (the carriage return and line feed characters), so the rule will not merge lines. [^0-9\n\r] means "any character that is neither a digit nor a line break". The complete rule retains digits and line breaks and removes all other characters.
Now you can copy the phone number (0732)65-43-21/123 to the clipboard, enter the form field for the phone number and type the abbreviation that triggers the above expansion, and you get: