Last active
August 23, 2026 20:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - 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