DT4K
Diamond Member
I need an expression that will match anything that falls within brackets in a string.
I'm using the Regex.Replace function in .Net, which is straightforward enough. I just pass the string, the pattern to search for, and the replacement string to replace everything that matches the pattern.
The trouble I'm having is trying to get the write regex pattern.
For example, I have a string that looks like:
bob397[C242], john235[B928]
and I want it to turn it into this:
bob397, john235
The first pattern I came up with was \[.*\]
This works fine if there is only one occurence of the bracketed values in the string. But in the above example, it replaces everything from the first open bracket to the last closing bracket. Like this:
bob397
Can anyone give me a pattern that will match anything that is within brackets?
Thanks
I'm using the Regex.Replace function in .Net, which is straightforward enough. I just pass the string, the pattern to search for, and the replacement string to replace everything that matches the pattern.
The trouble I'm having is trying to get the write regex pattern.
For example, I have a string that looks like:
bob397[C242], john235[B928]
and I want it to turn it into this:
bob397, john235
The first pattern I came up with was \[.*\]
This works fine if there is only one occurence of the bracketed values in the string. But in the above example, it replaces everything from the first open bracket to the last closing bracket. Like this:
bob397
Can anyone give me a pattern that will match anything that is within brackets?
Thanks