Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Stripping links from field

by GrandFather (Saint)
on Oct 24, 2022 at 22:49 UTC ( [id://11147659]=note: print w/replies, xml ) Need Help??


in reply to Stripping links from field

Sounds easy, but in practice it's tricky to catch just the link text. Here's a partial solution that will catch most links starting with https?://

use warnings; use strict; my $link = 'https://drive.google.com/file/d/1ZhXQYI-4fgx5hredv7Z0Tl2s +szvN92oV/view?usp=sharing'; my $text = <<TEXT; Some sample text to strip $link from. Sometimes the sentence ends with the $link. We don't want to remove th +e period if that happens, or other punctuation in similar situations. TEXT $text =~ s~\bhttps?://\S+([.)?!,]\s?|$|\b)~...$1~g; print $text;

Prints:

Some sample text to strip ... from. Sometimes the sentence ends with the .... We don't want to remove the +period if that happens, or other punctuation in similar situations.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Stripping links from field
by htmanning (Friar) on Oct 25, 2022 at 00:07 UTC
    Thanks so much. It works! I had resolved myself to simply not printing the $shortdesc if there was a URL included. This is much better.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found