Last active
February 16, 2026 15:06
-
-
Save HeyItsGilbert/df9baf0e92344662036f3f08283e4b99 to your computer and use it in GitHub Desktop.
Example of how you can build a complex regex on multiple lines with comments.
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
| $pattern = @' | |
| ^ # Beginning of the line | |
| # Get the hostname | |
| (?<hostname> | |
| # We have a DC name in the first 3 to 5 character | |
| (?<datacenter>.{3,5}) | |
| - # Literal dash | |
| # etc etc | |
| ) | |
| $ # End of the line | |
| '@ | |
| $options = [Text.RegularExpressions.RegexOptions]'IgnorePatternWhitespace' | |
| $regexMatch = [regex]::Match($HostName, $pattern, $options) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exactly. If you need a
#you gotta escape it, but other then that it can help with readability.