More values for requirements?

The requirements array offers quite a few values (Actions — PopClip Developer). What about a few more: digits (12, 123, 742323, …), letters (abc, foxtrott, PopClip) and – for those of us in science – doi (Digital object identifier - Wikipedia)?

This is more the purpose of the regex field, though it does require knowledge of regular expressions. For example:

#digits
regex: [0-9]+     # match the first run of digits in the selection
regex: ^[0-9]+$   # only selections with just digits


#letters
regex: ^[a-zA-Z]+$ # only selections with just letters

And I’m sure a suitable regex for doi could be made:

#doi
regex: (?i)10\.\d{4,9}/[-._;()/:A-Z0-9]+

That last one was from chatgpt, with helpful explanation at the link.

I can see some value in having some preset requirements that avoid the need to know how to write a regex, but it could never cover every need. Perhaps a “cookbook” page (like this) listing regexes for common use cases is the better approach.

I guess I still struggle to differentiate between the purpose of regex and requirement:

regex:

The action will appear only if the text matches the regex, and the matching part of the text is passed to the action.

requirements:

All the requirements in the array must be satisfied for the action to appear.

With e.g. url a string can be selected, when it contains an URL the action is visible but only the URL is passed. It can be narrowed down by using a regex like theguardian.com, so the action will only appear if there is a URL in the string and it contains the right web address.

How do I replicate this behaviour (a whole paragraph is selected and the action appears if a certain string within this paragraph is present and only the match is sent to the action) with regex? Can I work with capture groups here?

The „cookbook page“ sounds like a good idea.

Think of regex as being just another requirement.

For example if you set the regex to [0-9]+ and select text abc123def then it will match, and 123 will be sent to the action.

If you put ^[0-9]+$ then it will not match abc123def but it will match 123.

#popclip
name: Regex URL Example
regex: "[0-9]+"
url: https://example.com/***
# example input "foo 12345 bar" will match and open example.com/12345
#popclip
name: Regex JS Example
regex: "[0-9]+"
javascript: popclip.showText(popclip.input.matchedText)

You can also work with capture groups but only with JavaScript extensions, in which you can access the capture groups via popclip.input.regexResult which is an array.

#popclip
name: Capture Groups Example
regex: "(?i)([0-9]+)([a-z]+)"
javascript: popclip.showText(popclip.input.regexResult.join(","))
# example: input "123abc456" -> shows "123abc,123,abc"