in reply to Re: advance Regex
in thread advance Regex

Works fantastic. but can you explain the second and third regex to me? it will be your huge favour on me. this one:

$content =~ /(Putative.*?);/s; my $acids = $1; $acids =~ s/\n\s+/ /g;

and this one

$content =~ /TITLE\s*(.*?)\n\s+JOURNAL/s; my $aminoAcids = $1; $aminoAcids =~ s/\n\s+/ /g;

Replies are listed 'Best First'.
Re^3: advance Regex
by hippo (Archbishop) on Apr 28, 2020 at 13:15 UTC

    The first one says to capture everything from the first P of Putative up to but not including the first following semi-colon. Subsequently the whitespace is collapsed.

    The second one says to capture everything after "TITLE" and its trailing space(s) up to but not including a newline followed by whitespace followed by "JOURNAL" (which is the following key). Again, subsequently the whitespace is collapsed.

    Both of these require the /s modifier. See perldoc perlre for details of the modifiers. You can also fall back on YAPE::Regex::Explain for any regexen that you are having trouble understanding, although it doesn't include support for more modern features, alas.

      Thank you so much for explaining :)