Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Created August 15, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyelMorales/689907b2e65861c08217c7920da6a87c to your computer and use it in GitHub Desktop.
Save DanyelMorales/689907b2e65861c08217c7920da6a87c to your computer and use it in GitHub Desktop.
Helloworld.txt
#!/usr/bin/perl
undef $/;
$hostname = qr/[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info)/;
$text = <>;
$text =~ s/&/&amp;/g;
$text =~ s/</&lt;/g;
$text =~ s/>/&gt;/g;
$text =~ s/^\s*$/<p>/mg;
$text =~ s{
\b
# capture the address to one
(
\w[-.\w]* #username
\@
$hostname #hostname
)
\b
}{<a href='mailto:$1'>$1</a>}igx;
$text =~ s{
\b(
http:// $hostname #hostname
(
/[-a-z0-9_:\@&?=+,.!/~*'%\$]*
)?
)\b
}{
<a href='$1'>$1</a>
}gix;
print $text;
<h1>Hello world, foobar,</h1>
<h2>test</h2>
dvera@sunset.com dvera@sunset.com
http://hello.com
http://hello-aaaa.com

perl escaper.pl helloworld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment