下载此文档

Regular Expressions -正则表达式.ppt


文档分类:IT计算机 | 页数:约16页 举报非法文档有奖
1/16
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/16 下载此文档
文档列表 文档介绍
Regular Expressions
Luo Dan
2006-7-26
2017/11/12
1
Regular Expressions
Contents
Give a simple definiens
Give a simple example
Basic about perl regex syntax
A job to do immediately
(a email address: @)
Discuss
2017/11/12
2
Regular Expressions
Regex-Regular Expressions
A regular expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids.
For Example: *.txt
It can be written in Perl, PHP, Java, a .NET language or a multitude of other languages.
Here, I only describe regex in Perl.
2017/11/12
3
Regular Expressions
A Simple Example
#!/bin/perl
die ("You don't input a file name!\n") if !defined($ARGV[0]);
print ("Warning: without file!\n") if ($ARGV[0] !~ m/\w*/);
open (FILE, "<$ARGV[0]") or die ("Cannot open the file!\n");
***@lines = <FILE>;
close(FILE);
foreach $input (***@lines)
{
chomp($input);
if ($input =~ m/\w+/)
{
print ("$input\n");
}
}
2017/11/12
4
Regular Expressions
Perl's Regular Expression Operators
Matching: m//.
This operator returns true if PATTERN is found in $_.
Ex: m/hello/
Substitution: s///.
This operator replaces the sub-string matched by
PATTERN with REPLACEMENT.
Ex: s/hello/HELLO/
translation. tr///.
This operator replaces characters specified by CHARACTERS with the characters in REPLACEMENTS.
Ex: tr/ab/c/
The Binding Operators (=~ and !~)
2017/11/12
5
Regular Expressions
Option
Description
g
This option finds all occurrences of the pattern in the string. A list of matches is returned or you can iterate over the matches using a loop statement.
i
This option ignores the case of characters in the string.
m
This option treats the string as multiple lines. Perl does some optimization by assuming that $_ contains a single line of input. If you know that it contains multiple newline characters, use this option to turn off the optimization.
o
This piles the pattern only once. You can achieve some small perf

Regular Expressions -正则表达式 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数16
  • 收藏数0 收藏
  • 顶次数0
  • 上传人zbfc1172
  • 文件大小0 KB
  • 时间2013-01-09
最近更新