Is it possible to have a Remove Duplicate Words function?
thank popclip, always.
Is it possible to have a Remove Duplicate Words function?
thank popclip, always.
That’s an interesting one, can you give an example of what it would do exactly?
thanks for replied,
just like this site: Remove Duplicate Words and Repeated Keywords (tracemyip.org)
Use this RegEx with replace $1
\b(\w+)(?:\W+\1\b)+
Good bye bye world world
Becomes
Good bye world
Here’s that as a snippet:
#popclip - remove duplicated words, attempt 1
name: Remove Duplicates
icon: square dup
after: paste-result
javascript: |
const regex = /\b(\w+)(?:\W+\1\b)+/g
return popclip.input.text.replace(regex, (_, word) => word)
(The above block is an extension snippet - select it to install the extension with PopClip)
Pretty good but it only removes duplicates that are adjacent, so: one one two two
→ one two
,
but: one two two one
→ one two one
Let me try another approach:
#popclip - remove duplicated words attempt 2
name: Remove Duplicates
icon: square dup
after: paste-result
javascript: |
const words = popclip.input.text.split(/\s/)
return [...new Set(words)].join(' ')
// technique thanks to <https://stackoverflow.com/a/14438954/220847>
// also note: "iteration of sets visits items in insertion order" (MDN)
This time: one two two one
→ one two
you guys are geniuses
remove duplicate lines:
#popclip - remove duplicate lines
name: Remove Duplicate Lines
icon: square dup
after: paste-result
javascript: |
const lines = popclip.input.text.split(/\n/)
return [...new Set(lines)].join('\n')
eval()
each line
#popclip - eval lines
name: JS eval() Lines
icon: iconify:pepicons-pop:code
after: paste-result
javascript: |
const lines = popclip.input.text.split(/\n/)
return lines.map(l => eval(l)).join('\n')
really nice for inline math mutations and replace with result:
I’m impressed that it works with the multi-selection!!