in reply to regular expression

Assuming the "name" is the LAST entry inside square brackets, you can use something like this:
perl -e '(@x)=$ARGV[0]=~/\[(.*?)\]/g; print qq|$x[$#x];\n|' "enoyl-[a +cyl-carrier-protein] reductase [NADH] 2 [Silicibacter sp. TrichCH4B]. + " #--output--- Silicibacter sp. TrichCH4B;
Also, the regular expression is probably better written as:
/\[([^\]]+)\]/
(But that assumes matching "]" are guaranteed.)

             All great truths begin as blasphemies.
                   ― George Bernard Shaw, writer, Nobel laureate (1856-1950)

Replies are listed 'Best First'.
Re^2: regular expression
by muppetjones (Novice) on Mar 16, 2012 at 18:47 UTC

    As a side note, NetWallah's solution calls perl from the command line -- if you wanted to use it in your code, do this:

    while ($desc =~ /\[(.*?)\]/g) { } $org = $1 or '';
    or
    $desc =~ s/\[(.*?)\]//g; $org = $1 or '';

    The regex used essentially matches all data within brackets, but only saves the last one. The first example uses m//, and must therefore be run through a loop as the /g modifier merely saves the place where the previous regex match ended.

    The second option will destroy the string stored in $desc, but does not require the loop.