in reply to Re^2: To Match the text
in thread To Match the text

First, when you post perl code, put "<c>" or "<code>" at the beginning of the code, and "</c>" or "<code>" at the end, so that it will display correctly.

Your regex has a few problems:

  1. try putting "+" after each "\d" in the captured region, so that you can match "54" as well as "5";
  2. you are using the "e" modifier at the end, which says that the replacement string should be executed as a snippet of perl code, but your replacement string is not perl code;
  3. you say you want to capture a whole string like "5-7, 54, 59f-60d, 90, 114", but your regex (when it works) will only capture the pieces between commas, and return these as a list.

If you just want to remove the initial part, that's a simpler job:

$var = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; $var =~ s/^\S+\s+\d+,\s*//; # remove first word and digit string
If you also want the remainder to be broken into separate pieces, use split:
my @pieces = split /,\s*/, $var;
In fact, split by itself could do both things at once:
$var = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; my ( $junk, @pieces ) = split /,\s*/, $var;
(updated to fix last snippet)