Richard wrote:
We have a bunch of strings in the following format:
[xxxxx] yyyy [xxxxx] yyyyy
We would like to keep all of the "xxxxx" data - anything that falls within
the square brackets. We know that Regex can do this but, whooaa - how do
you
make it do this?
In addition to PW's suggestion, you can also get the modified string back
from a regex replacement in one go. Just call Regex.Replace to replace this:
(?<!\[[^\]]*)[^\[\]]*(?![^\[]*\])
by nothing (just pass in an empty string for the replacement parameter. It
should return
[xxxxx][xxxxx]
for your sample above.
If you want to get rid of the brackets themselves as well, use this
expression instead:
\]?(?<!\[[^\]]*)[^\[\]]*(?![^\[]*\])\[?
This will give the result
xxxxxxxxxx
for your sample.
Looks a bit like line noise, doesn't it? :-)
Oliver Sturm
--
Expert programming and consulting services available
See
http://www.sturmnet.org (try /blog as well)