Last active
February 9, 2025 12:03
-
-
Save crazytyper/06c21655051dfb55016bbb7f91bb78ad to your computer and use it in GitHub Desktop.
Naive glob to regex. Does not work for π and π¦
This file contains 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
function Convert-GlobToRegex([string] $pattern) | |
{ | |
$regex = $pattern -replace '\*\*(/|\\)', 'π' ` | |
-replace '\\', '\\' ` | |
-replace '\*\*', 'π¦' ` | |
-replace '\*', '[^/\\]*' ` | |
-replace '\.', '\.' ` | |
-replace 'π', '(.*(/|\\))?' ` | |
-replace 'π¦', '.*' | |
"^$regex$" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment