Mastering Regular Expression 代码介绍 3 - HTML 格式转换
来源:互联网 发布:打印排版软件有哪些 编辑:程序博客网 时间:2024/06/05 21:23
#! /usr/bin/perl
$text = <>; # Slurp up the first file given on the command line.
$text =~ s/&/&/g; # Make the basic HTML . . .
$text =~ s/</</g; # . . . characters &, <, and > . . .
$text =~ s/>/>/g; # . . . HTML safe.
$text =~ s/^\s+$/<p>/mg; # Separate paragraphs.
$HostnameRegex = qr/[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info)/i;
# Turn email addresses into links . . .
$text =~ s{
\b
# Capture the address to $1 . . .
(
\w[-.\w]* # username
\@
$HostnameRegex # hostname
)
\b
}{<a href="mailto:$1">$1</a>}gix;
# Turn HTTP URLs into links . . .
$text =~ s{
\b
# Capture the URL to $1 . . .
(
http:// $HostnameRegex \b # hostname
(
/ [-a-z0-9_:\@&?=+,.!/~*'%\$]* # Optional path
(?<![.,?!]) # not allowed to end with [.,?!]
)?
)
}{<a href="$1">$1</a>}gix;
print $text;
#完整版,综合代码介绍1,2
$text = <>; # Slurp up the first file given on the command line.
$text =~ s/&/&/g; # Make the basic HTML . . .
$text =~ s/</</g; # . . . characters &, <, and > . . .
$text =~ s/>/>/g; # . . . HTML safe.
$text =~ s/^\s+$/<p>/mg; # Separate paragraphs.
$HostnameRegex = qr/[-a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info)/i;
# Turn email addresses into links . . .
$text =~ s{
\b
# Capture the address to $1 . . .
(
\w[-.\w]* # username
\@
$HostnameRegex # hostname
)
\b
}{<a href="mailto:$1">$1</a>}gix;
# Turn HTTP URLs into links . . .
$text =~ s{
\b
# Capture the URL to $1 . . .
(
http:// $HostnameRegex \b # hostname
(
/ [-a-z0-9_:\@&?=+,.!/~*'%\$]* # Optional path
(?<![.,?!]) # not allowed to end with [.,?!]
)?
)
}{<a href="$1">$1</a>}gix;
print $text;
- Mastering Regular Expression 代码介绍 3 - HTML 格式转换
- Mastering Regular Expression 代码介绍 1 - HTML 格式转换
- Mastering Regular Expression 代码介绍 2 - HTML 格式转换
- Mastering Regular Expression 代码介绍 - 摄氏度 华氏度 转换
- Mastering Regular Expression 代码介绍 1 - 重复单词处理
- Mastering Regular Expression - 介绍 1 ( lookahead 光看不吃 )
- O'Reilly: mastering regular expression读中感
- O'Reilly: mastering regular expression读中感2
- LeetCode Regular Expression Matching 极品代码赏析
- Mastering Regular Expressions [ILLUSTRATED]
- regular expression
- Regular Expression
- regular expression
- Regular Expression
- Regular Expression
- regular expression
- Regular Expression
- Regular Expression
- C# 实现磁性窗口(附源码和程序)
- 如何生活
- 移动应用VS浏览器:HTML5或彻底改变竞争格局
- C语言中最常用标准库函数
- syntax error near unexpected token `then' ./sleep.sh: line 8: ` then let count++;'
- Mastering Regular Expression 代码介绍 3 - HTML 格式转换
- 吸引人的产品
- grep同时两个匹配条件
- 读书与开矿
- 编译OWASP WebScarab (续)
- 何处买青春
- mysql忘记root密码拯救方法(flush privileges)
- 如何调节Eclipse下console输出字体的大小??
- 希望与厄运