Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Regex string trimming help

by johnfl68 (Beadle)
on Dec 19, 2016 at 00:12 UTC ( #1178018=perlquestion: print w/replies, xml ) Need Help??
johnfl68 has asked for the wisdom of the Perl Monks concerning the following question:

Hello

I had this figured out at one time, then changed the way I did things and didn't really need it, but now I need it again for a few instances.

Unfortunately I can not find the final version that I actually used.

I am trying to trim down a string from NWS weather alerts. Here is an example:

...FLASH FREEZE AND AREAS OF BLACK ICE... Temperatures will continue t +o fall in the wake of a strong cold front as brisk and gusty west to +northwest winds usher in much colder air. As temperatures drop into t +he 20s lingering standing water on roads and other untreated surfaces + will freeze up creating hazardous driving and walking conditions. In + addition,

All I need is what is between the first "..." and the second "..." and nothing else.

...FLASH FREEZE AND AREAS OF BLACK ICE...

Sometimes they use the 3 dot pattern in more than one place, I only really want the first set.

What I could find that was the last entry in my notes is this:

$summary =~ s/\Q...\E/.../g;

But that is not working correctly. I have tried a few other ways, but I am not having any luck.

Any help would be greatly appreciated as always. Thank you!

Replies are listed 'Best First'.
Re: Regex string trimming help
by choroba (Bishop) on Dec 19, 2016 at 00:21 UTC
    You can split the string on three dots and select the second part:
    my $result = (split /\Q...\E/, $summary)[1];

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Regex string trimming help
by tybalt89 (Priest) on Dec 19, 2016 at 00:25 UTC
    #!/usr/bin/perl -l # http://perlmonks.org/?node_id=1178018 use strict; use warnings; while(<DATA>) { print /\.{3}(.*?)\.{3}/; } __DATA__ ...FLASH FREEZE AND AREAS OF BLACK ICE... Temperatures will continue t +o fall in the wake of a strong cold front as brisk and gusty west to +northwest winds usher in much colder air. As temperatures drop into t +he 20s lingering standing water on roads and other untreated surfaces + will freeze up creating hazardous driving and walking conditions. In + addition,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1178018]
Approved by beech
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2018-07-18 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (393 votes). Check out past polls.

    Notices?