Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a set of file-names in this format:

XYX_WT_7_25h_Trimmed_75.SAM

And I want to match the second to last _ and all text after it (_Trimmed_75.SAM). Ordinarily I would use:

/_[^_]+$/

To grab everything after the final _ but being new to Perl i'm not sure how I would do this for the second to last. Any help would be much appreciated!

Replies are listed 'Best First'.
Re: Matching all text after a specific character
by Athanasius (Archbishop) on Aug 24, 2016 at 13:30 UTC
Re: Matching all text after a specific character
by Anonymous Monk on Aug 24, 2016 at 14:36 UTC
    #!/usr/bin/perl -l # http://perlmonks.org/?node_id=1170310 use strict; use warnings; while(<DATA>) { /.*(_.*_.*)/ and print $1; } __DATA__ XYX_WT_7_25h_Trimmed_75.SAM some_other_name bad_name one_two_three_four_five_six