Regular Expression to find a string included between two characters while EXCLUDING the delimiters

前端 未结 12 2510
旧时难觅i
旧时难觅i 2020-11-21 23:49

I need to extract from a string a set of characters which are included between two delimiters, without returning the delimiters themselves.

A simple example should b

12条回答
  •  青春惊慌失措
    2020-11-22 00:18

    You just need to 'capture' the bit between the brackets.

    \[(.*?)\]
    

    To capture you put it inside parentheses. You do not say which language this is using. In Perl for example, you would access this using the $1 variable.

    my $string ='This is the match [more or less]';
    $string =~ /\[(.*?)\]/;
    print "match:$1\n";
    

    Other languages will have different mechanisms. C#, for example, uses the Match collection class, I believe.

提交回复
热议问题