CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [puchu] Regex on multiple lines for Science: Edit Log



Kenosis
User

Apr 5, 2013, 7:27 PM


Views: 608
Re: [puchu] Regex on multiple lines for Science

Here's another option:


Code
use strict; 
use warnings;

my $data = do { local $/; <> };
$data = $1 and $data =~ s/\s+//g if $data =~ /(?<=SEQUENCE)(.+)(?>Entry Created)/s;
print $data;


Usage: perl script.pl inFile [>outFile]

The last, optional parameter will direct output to a file.

The above first slurps the file into a single variable. It then uses a regex to capture the sequence, and a substitution to remove all whitespace.

Hope this helps!


(This post was edited by Kenosis on Apr 5, 2013, 8:07 PM)


Edit Log:
Post edited by Kenosis (User) on Apr 5, 2013, 7:38 PM
Post edited by Kenosis (User) on Apr 5, 2013, 8:01 PM
Post edited by Kenosis (User) on Apr 5, 2013, 8:02 PM
Post edited by Kenosis (User) on Apr 5, 2013, 8:07 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives