-3

how to get the value between first { and last } from a string which have multiple {}.

eg string:  ".....[object:{ ..{...{..}...}..}]"

My approach using C#:

line="abcd..efg..[object:{ ab{..c{d.}.e.}f....g}]"
string p = ".*\\[Object:{([A-Za-z{}]*)}\\]";
Regex r = new Regex(p);
Match m=r.match(line);
string value=m.Groups[1].Value.ToString();

Result should be:

value= ab{..c{d.}.e.}f....g
shubham gupta
  • 321
  • 3
  • 9
  • 23
  • You should post ur attempts ,test string,expected result!!!!! seems more like a `chat` :) – vks Apr 16 '15 at 12:29
  • possible duplicate of [Get values between curly braces c#](http://stackoverflow.com/questions/17379482/get-values-between-curly-braces-c-sharp) or [Regex to get string between curly braces “{I want what's between the curly braces}”](http://stackoverflow.com/questions/413071/regex-to-get-string-between-curly-braces-i-want-whats-between-the-curly-brace) – Wiktor Stribiżew Apr 16 '15 at 12:30
  • @vks i'll keep that in mind from now on :D – shubham gupta Apr 16 '15 at 12:42

1 Answers1

1
{.*}

or

(?<={).*(?=})

This should do the trick for you.See demo

string strRegex = @"{.*}";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline);
string strTargetString = @".....[object:{ ..{...{..}...}..}]";

foreach (Match myMatch in myRegex.Matches(strTargetString))
{
  if (myMatch.Success)
  {
     // Add your code here
  }
}
vks
  • 67,027
  • 10
  • 91
  • 124