How do I improve my Perl regex to handle the __DATA__ below?
my ($type, $value) =~ /<(\w+)\s+(.*?)\(\)>/;
__DATA__
<dynamic DynamicVar>
<dynamic DynamicVar > # not need attache the blackspace to $value when return
<dynamic DynamicFun()>
<dynamic DynamicFun() > # not need attache the blackspace to $value when return
I want to return the $type and $value as this format <$type $value>.
Rather than worrying about the details of the contents, just match anything inside the brackets.
.*?means to match anything non-greedy which means it will look for the first thing to match, rather than the longest. This means it won’t pick up whitespace at the end, it will leave it to the\s*. It also means it won’t be fooled by<foo bar> and then a >.