I use TextExpander and copy dates frequently and have numerous expands, including dates in this format: 10/30/2022. When I save a file with the “/” included, it gives windows user problems, and I re-format it to a “.” or a“ -” instead. -
Is there a chance a ReplaceSlashbetween words withDash, and vice versa, and a ReplaceSlashbetween words with a Period could be considered?
My Solution
This one is fairly easy with a JavaScript action:
This is terrific. But dare I ask for something that would be absolute BRILLIANT? What about something would convert the order to ISO 8061 YYYY-MM-DD?
So, in that case, 10/30/2022 would become 2022-10-30. There would need to be a version for US (MM/DD/YYYY) and the rest of the world (DD/MM/YYYY), but presumably that could be an option. This woudl be really useful!
#popclip
name: US Date to ISO
icon: circle filled MDY
after: paste-result
javascript: |
const regex = /(\d{2})\/(\d{2})\/(\d{4})/g
const replacer = (_, m, d, y) => `${y}-${m}-${d}`
return popclip.input.text.replace(regex, replacer)
I’ll leave the rest-of-world version as an exercise for the reader
Actually, for ISO 8601, the next-to-last line needs to be year, month, day: ${y}-${m}-${d}
#popclip
name: US Date to ISO
icon: circle filled MDY
after: paste-result
javascript: |
const regex = /(\d{2})\/(\d{2})\/(\d{4})/g
const replacer = (_, m, d, y) => `${y}-${m}-${d}`
return popclip.input.text.replace(regex, replacer)
#popclip
name: EURO Date to ISO
icon: circle filled DMY
after: paste-result
javascript: |
const regex = /(\d{2})\/(\d{2})\/(\d{4})/g
const replacer = (_, d, m, y) => `${y}-${m}-${d}`
return popclip.input.text.replace(regex, replacer)
Thank you so much! Your code worked for me as is but I’m trying to tweak the regex input to convert a full date, like December 30, 2023 to 2023-12-30 format. Any ideas how this can be done? I’m not very familiar with regex, tried something like \w{3,9}?\s\d{1,2}?\s?,\s\d{4}? but got invalid escape error.