Skip to content

Instantly share code, notes, and snippets.

@smeech
Last active August 23, 2026 20:32
Show Gist options
  • Select an option

  • Save smeech/c9da9041c4272ce145ec59f8e2ff6bb6 to your computer and use it in GitHub Desktop.

Select an option

Save smeech/c9da9041c4272ce145ec59f8e2ff6bb6 to your computer and use it in GitHub Desktop.
[HTML tags] Accept an indeterminate number of parameters in a regex: trigger by returnng empty strings afterwards, for a script to handle. #espanso #Python #PowerShell
- regex: '<(?P<words>[a-zA-Z]+(?: [a-zA-Z]+){0,3})>'
replace: '{{output}}'
vars:
- name: output
type: shell
params:
shell: pwsh # In Windows you can omit or specify powershell
cmd: |
$names = "{{words}}" -split '\s+'
$opens = ($names | ForEach-Object { "<$_>" }) -join ""
$closesArr = $names.Clone()
[Array]::Reverse($closesArr)
$closes = ($closesArr | ForEach-Object { "</$_>" }) -join ""
Write-Output "$opens`$|`$$closes"
- regex: '<(?P<words>[a-zA-Z]+(?: [a-zA-Z]+){0,3})>'
replace: "{{output}}"
vars:
- name: output
type: script
params:
args:
- python3
- -c
- |
names = "{{words}}".split()
opens = "".join(f"<{n}>" for n in names)
closes = "".join(f"</{n}>" for n in reversed(names))
print(f"{opens}$|${closes}", end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment