Skip to content

Custom command to capture six digit numbers #2707

@realchrisolin

Description

@realchrisolin

I've been trying since last week to come up with a custom command that will automatically fire when text with a six digit number is copied and copy only the six digit number to a separate tab. Through a lot of trial and error, I've gotten close but am having ongoing issues getting this to perform correctly. At this point, I'm not sure if the issue is a bug in CopyQ, Qt, or something wrong with my code (although I think this is a bug).

Specifically, the two major issues I've had is getting CopyQ to keep copying text regardless if a six digit number is in the copied string and getting it to parse out just the six digit number into the separate tab.. If I create a new command where Advanced > Content is set to \b\d{6}\b, the command will fire on any string with a six digit number. However, the %1 expression contains the entire copied string, not the matched text.

The closest I've got to sanitizing copied text that matches on that regex is the following command, but I can't get the regex to capture the six digit number correctly either as a match or with a capture group in the expression. Both match[0] and match[1] return the fully copied string instead of just the six digit number.

copyq popup match
var clipboardText = %1;
var regex = /\b(\d{6})\b/;
var match = regex.exec(clipboardText);
if (match) {
  setClipboard(match[1]);
  write("recent tickets", match[1]);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions