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.