Conditional text formatting

What is the easiest way to implement this logic to the text in Clipboard:

  • if text string in Clipboard begins with +7, then do nothing
  • if text string in Clipboard begins with 8, then replace it (this digit) with +7
  • if text string in Clipboard begins with any other digit, then add +7 to the beginning of this string

I think this is what you're asking for:

In the regular expression:

^8    "^" means "starts with".
^+7   "^" means "starts with", and "\+" means the character "+"
          (the "\" is an "escape character", since in regular expressions,
          "+" has a special meaning).

So, this says : If the clipboard starts with 8, chang it to start with +7 instead. Otherwise, if it does not start with +7,
prepend +7.

2 Likes

Works like a charm!
Thank you very much, Dan!

1 Like