Created
April 9, 2013 09:16
-
-
Save theorigin/5344279 to your computer and use it in GitHub Desktop.
RegEx to wrap [ ] around text. For example when you need to turn a single JSON object into an array.
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
/// A description of the regular expression: | |
/// | |
/// Beginning of line or string | |
/// [1]: A numbered capture group. [[^[].*[^]]] | |
/// [^[].*[^]] | |
/// Any character that is NOT in this class: [[] | |
/// Any character, any number of repetitions | |
/// Any character that is NOT in this class: []] | |
/// End of line or string | |
var regex = new Regex("^([^[].*[^]])$", RegexOptions.CultureInvariant | RegexOptions.Compiled); | |
var result = regex.Replace(replacements, "[$1]"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment