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

Hi

I need help writing a syntax from a text. Explicitly, my string is this (without quotes): "../AGH-final/agh_merged1_no7.csv"

I need to extract the "agh" portion between last / and first _ by looking for these two referenced characters and getting what is in between. I will need this into one command, e.g. something to be inserted into a code like: $var1 =~ thisMagicSyntax;

Thank you very much!

PS: the AGH and agh parts are texts that are changing, so I can't really use them as a reference of sort s/(?<=agh_)....etc

  • Comment on extract text between two delimiters from a text line

Replies are listed 'Best First'.
Re: extract text between two delimiters from a text line
by GrandFather (Saint) on Dec 02, 2011 at 02:31 UTC
    use strict; use warnings; my $str = '../BAC-final/bac_merged1_no9.csv'; my ($substr) = $str =~ m!.*/([^_]*)_!; print "'$substr'";

    Prints:

    'bac'
    True laziness is hard work

      thanks for saving me, GrandFather. Your solution just as I needed.

      Many, many, thanks!