Does this line of Perl really do anything?
$variable =~ s/^(\d+)\b/$1/sg;
The only thing I can think of is that $1 or $& might be re-used, but it is immediately followed by.
$variable =~ s/\D//sg;
With these two lines together, is the first line meaningless and removable? It seems like it would be, but I have seen it multiple times in this old program, and wanted to make sure.
^at the beginning makes the/gmodifier useless..in the string makes the/smodifier useless, since it serves to make.also match newline.\band^are zero-width assertions, and the only things outside the capture group, this substitution will not change the variable at all.The only thing this regex does is capture the digits into
$1, if they are found.The subsequent regex
Will remove all non-digits, making the variable just one long number. If one wanted to separate the first part (matched by the first regex), the only way to do so would be by accessing
$1from the first regex.However, the first regex in that case would be better written simply:
And if the capture is supposed to be used: