1 Command CBRegex
steve-px edited this page 2026-07-07 13:22:28 +00:00

🢐🢐 Index ‖ 🢐 Previous Page | Next Page 🢒


[-] Appendix A2 - Console Commands

Command: CBREGEX

Syntax

CBREGEX <option>

Options

  • CBREGEX --ls - List all the rules.
  • CBREGEX --remove <Int: RuleId> - Removes a rule.
  • CBREGEX --enpat <Int:RuleId> - Enables a rule.
  • CBREGEX --dispat <Int:RuleId> - Disables a rule.

Creating a Rule


CBREGEX --pattern <String:Regex>
          --replace <String:ReplacePattern>
          [--remove-chars <String:Chars>]
          [--description <String:Text>]
          [--prompt <String:Text>]
          [--prompt-pattern <String:Regex>]

Parameters:

Parameter Description
--pattern The regular expression used to match clipboard content.
--replace The replacement pattern used to generate the transformed text.
--remove-chars Optional list of characters to remove from the clipboard text before processing.
--description Optional description of the rule.
--prompt Optional prompt displayed to the user when additional input is required.
--prompt-pattern Optional regular expression that validates the user's response to the prompt.

Description

The CBREGEX command manages clipboard automation rules.

Whenever text is copied to the system clipboard, CBREGEX evaluates the clipboard contents against all registered rules. If a rule matches, the copied text is automatically transformed according to the rule's replacement pattern.

This feature can significantly reduce manual editing when repeatedly copying data that requires reformatting before being pasted into another application.

For example, numeric values copied from reports or spreadsheets may contain unwanted leading or trailing whitespace. Instead of manually removing the whitespace each time, a CBREGEX rule can perform the cleanup automatically whenever the value is copied.

Enabling the Feature

Clipboard automation is disabled by default. To enable it, set the console variable:

cv_cbregex_enabled true

Examples

Remove Leading and Trailing Whitespace from Numbers

The following rule matches numeric values and removes surrounding whitespaces:

cbregex --pattern "^\\s*(\\d+)\\s*$" \
        --replace "%1%" \
        --description "Match any number"

Normalize Email Addresses

The following rule matches email addresses and removes leading or trailing whitespaces:

cbregex --pattern "^\\s*([A-Za-z0-9+_.-]+)@([A-Za-z0-9+_.-]+)\\.([A-Za-z0-9]+)\\s*$" \
        --replace "%1%@%2%.%3%" \
        --description "Match an email address"

Regular Expressions

To use CBREGEX effectively, you should have a basic understanding of regular expressions (commonly abbreviated as regex).

A regular expression is a sequence of characters that defines a search pattern. When clipboard content matches the pattern, CBREGEX can extract portions of the text into groups and use those groups to build a replacement string.

This guide does not cover regular-expression syntax in detail, as it is a comprehensive language in its own right. If you are new to regex, the following resources are recommended:

Regex101 is particularly useful for developing and testing regular expressions before using them in CBREGEX rules.

Escaping Characters

Please note that certain regular-expression characters may also require escaping for the console parser.

For example:

  • A single backslash (\) must be entered as \\
  • A double backslash (\\) must be entered as \\\\

Other special characters, such as $, may also require escaping depending on the context.

Replacement Patterns

Replacement patterns are simpler than regular expressions.

In the regex pattern, you define capture groups using parentheses. In the replacement pattern, those captured values can be referenced using the group number enclosed in percent signs (%).

Capture Group References

  • %1% - First capture group
  • %2% - Second capture group
  • %3% - Third capture group
  • ... - Additional capture groups

For example, %2% inserts the contents of the second capture group into the replacement string.

User Prompt Responses

If the rule uses the --prompt option, the user's response can be inserted into the replacement string using %PROMPT. This placeholder is replaced with the value entered by the user when the rule is executed.

An example of such a rule:

cbregex --pattern "^\\s*(\\d+)(\\s*|/)(\\d+)\\s*(\\d+)\\s*(\\d+)\\s*$" \
        --replace "%PROMPT%-%1%-%3%-%4%-%5%" \
        --prompt "NET/LDC? (ex: 03DEU0000)" \
        --prompt-pattern "^([0-9]{2}[a-zA-Z]{3}0)([0-9]{3})$" \
        --description "Matches and re-formats a BSS position without the net. Prompts the user for the net."

When the users copies something to the clipboard that matches the pattern in the rule above, a prompt will appear:

Alt-Test

And if --prompt-pattern was defined in the rule, and the user inputs something that does not match that pattern, it will mark the field in yellow to indicate that the input is invalid:

Alt-Test


🢐🢐 Index ‖ 🢐 Previous Page | Next Page 🢒