Capture text between two known characters

4

I need to get some text and find the words (or phrases) that are between two specific characters { and } , in this case.

>

I can do this by capturing the delimiters together, using the expression {(.*?)} , but I need the string to come without the two limit characters ( {} ).

I've tagged but I accept regex that does not use regex .

    
asked by anonymous 13.01.2016 / 17:57

2 answers

4

Solution in Regex:

  • With {}

    Regex r = new Regex(@"\{[^\}]+?\}");
    Match m = r.Match(text);
    
  • No {} :

    Regex r = new Regex(@"(?<=\{)[^\}]+?(?=\})");
    Match m = r.Match(text);
    

See .netFiddle

    
13.01.2016 / 18:01
1

The expression:

([a-z0-9])+(?=\})
    
13.01.2016 / 18:09