Skip to content

Instantly share code, notes, and snippets.

@crazytyper
Last active February 9, 2025 12:03
Show Gist options
  • Save crazytyper/06c21655051dfb55016bbb7f91bb78ad to your computer and use it in GitHub Desktop.
Save crazytyper/06c21655051dfb55016bbb7f91bb78ad to your computer and use it in GitHub Desktop.
Naive glob to regex. Does not work for 🌈 and πŸ¦„
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