Last active
September 19, 2024 20:42
-
-
Save Fasteroid/94c634f1d6ed16069461016b607bd123 to your computer and use it in GitHub Desktop.
Substitution regex for adding spaces around braces. Works on regex101 but seems broken in Visual Studio...
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
(""(?>[^""]|\\"")*?"")|(?!\( )(\()(?!\))(\1??(?>(?>""(?>[^""]|\\"")*?"")|.){4,})(\))(?<! \)) | |
$1$2 $3 $4 | |
For use in Visual Studio (.NET Regex Engine) | |
FEATURES | |
- Inserts space after opening and before closing parenthesis if contents between parentheses is longer than <x> (4 in this example) | |
- Does not do anything to strings | |
- Ignores parentheses that already have space | |
- Can be used multiple times to hit nested offenders | |
BUGS | |
- Inserts 2 spaces after some strings (could fix this if .NET had conditional replacements) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment