Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: advance Regex

by shabird (Sexton)
on Apr 28, 2020 at 13:01 UTC ( [id://11116159]=note: print w/replies, xml ) Need Help??


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 (Bishop) 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 :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11116159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found