I'm trying to capture a substring using regex capturing with grep by getting the content of (.*) in the code below.
@substring = grep /^test-results(.*)/,@$(array_reference);
This is not working....
Perl Matching Operator =~The matching operator =~ is used to match a word in the given string. It is case sensitive, means if string has a lowercase letter and you are searching for an uppercase letter then it will not match.
Regular Expression (Regex or Regexp or RE) in Perl is a special text string for describing a search pattern within a given text. Regex in Perl is linked to the host language and is not the same as in PHP, Python, etc. Sometimes it is termed as “Perl 5 Compatible Regular Expressions“.
$1 equals the text " brown ".
In list context, a regex match returns a list of what its captures matched, so all you need is:
@substrings = map /^test-results(.*)/, @$array;
Probably the map
function is a better fit for what you want. You're looking for something similar to the following (untested) code:
@substrings = map { /^test-results(.*)/ ? $1 : () } @{ $arrayref };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With