Save parts of the text to different named clipboards

Hello!

My goal is to copy all the text and save parts of it to different named clipboards: 1111222233334444 05/66 789
I want to save:
“1111222233334444” to named clipboard 1
"05" to named clipboard 2
"66" to named clipboard 3
"789" to named clipboard 4

The text to copy will be different every time.

Is it possible?

Thanks in advance!

How will it be different? How is it to be split in to four parts?

Knowing that, it is probably very easy to do.

It will be in the same format just different digits, the number of digits will be the same: 1111222233334444 05/66 789 or 4444666677779999 07/89 987 or 3456765487651234 77/22 789

Not sure how to split, probably copy first 16 digits then next 2, next 2 and next three.

Found a solution of this with split text action

Here is an example using RegEx to extract the numbers and store in variables. I highly recommend using KM Variables instead of Named Clipboards if you are just storing text. You need Clipboards only if you are storing images, objects, or styled text.

If you want to make the KM Variables available to other macros and/or subsequent executions of this macro, just remove the prefix of "Local__" from each variable. This makes them global Variables. I would probably replace with a common prefix like "DND_NFS__" where:

  • "DND" -- stands for "Do Not Delete"
  • "NFS" -- stands for "Numbers From String"
    • I'd probably use an acronym that reflects the content

Questions?


Example Results

image

Here is the RegEx:
(\d{16})\h+(\d{2})\/(\d{2})\h+(\d{3})

See the explanation of it here:

Macro: Extract Numbers from String via RegEx [Example]

Extract Numbers from String via RegEx [Example].kmmacros (3.5 KB)

image

3 Likes

Thanks a lot for the macro, will work on it. :+1:

No problem. Let us know if you have any questions.

1 Like

JMichaelTX,

Is there a way to ignore some symbols like commas or dots?
In some cases there is a dot or a comma “4941605601140387. 05/26 769”

Sure. Just change the regular expression used in the “Extract Numbers using RegEx (Search)” action to this:

(\d{16})[.,\h]+(\d{2})\/(\d{2})\h+(\d{3})

2 Likes

Thanks a lot, still too much to study :notebook:

Guys, the next part of my macro is to set a condition and fill a web form with month (01-12) / year (2018-2043)

If the variable Local_Num2 = 01 then type text Jan, If 02 then type Feb etc...
If the variable Local_Num3 = 18 then type text 2018, of 2019 then type 2019 etc...

Should i use IF action multiple times and set a condition for every month / year or there is a way to make it more simple?

Thanks in advance

No problem, @kreal. Assuming you're running KM8 there is indeed a simpler way to do this, by using a dictionary. First, download and run this macro (feel free to edit it to suit your needs):

Make Calendar Dictionary.kmmacros (3.9 KB)
30 PM

Once that's done, and the dictionary has been created, you can then use your variable to reference the appropriate key value like this:

%Dictionary[Months,%Variable%Num2%]%
42 PM5

In your case, you can just use an Insert Text action with the same syntax, no If Then Else action required:

54 PM

As for the year, that's easier than you might think. Since it sounds like the Num3 variable will always be the last two digits of the year, and you know you'll be sticking to years prefixed with "20", you can just do this:

15 PM
5

Make sense? Feel free to ask post again if anything is unclear!

2 Likes

This is just perfect, much appreciated!

1 Like

One more question:

How can i ignore all whitespaces between first 16 digits, in case there are some?

For example: 111122 22333 34444

Hey Kirill,

Something like this would probably work:

\d(\d\h?){14}\d

-Chris

I believe that my original macro solved your first request. Here's an updated macro that handles your additional requirements. Please let us know if you have further questions.

So here is the test string I used for development/validation:

1 111 22 22333 344 44. 05/18 789
1111222233334444 05/66 789
4444666677779999. 07/89 987
3456765487651234 77/22 789

Example Results

image

MACRO:   Extract Numbers from String via RegEx [Example]


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/9/a/9a5360a8ba27a27efb64ce2649aa7aaccf1a4e58.kmmacros">Extract Numbers from String via RegEx [Example].kmmacros</a> (6.3 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

### ReleaseNotes

See https://regex101.com/r/Es2T8r/3

---

![image|525x1366](upload://kkKY55IizzlPy2SlNWwoBJEQMbo.jpg)

Thank you guys, both answers are solving my questions!