来自正则表达式大师的作品

原创 2005年02月26日 19:40:00
Introduction to Regular Expressions Here's the scenario: you're given the job of checking the pages on a web server for doubled words (such as "this this"), a common problem with documents subject to heavy editing. Your job is to create a solution that will: Accept any number of files to check, report each line of each file that has doubled words, highlight (using standard ANSI escape sequences) each doubled word, and ensure that the source filename appears with each line in the report. Work across lines, even finding situations where a word at the end of one line is repeated at the beginning of the next. Find doubled words despite capitalization differences, such as with 'The the···', as well as allow differing amounts of whitespace (spaces, tabs, newlines, and the like) to lie between the words. Find doubled words even when separated by HTML tags. HTML tags are for marking up text on World Wide Web pages, for example, to make a word bold: '···it is very very important···'. That's certainly a tall order! But, it's a real problem that needs to be solved. At one point while working on the manuscript for this book, I ran such a tool on what I'd written so far and was surprised at the way numerous doubled words had crept in. There are many programming languages one could use to solve the problem, but one with regular expression support can make the job substantially easier. Regular expressions are the key to powerful, flexible, and efficient text processing. Regular expressions themselves, with a general pattern notation almost like a mini programming language, allow you to describe and parse text. With additional support provided by the particular tool being used, regular expressions can add, remove, isolate, and generally fold, spindle, and mutilate all kinds of text and data. It might be as simple as a text editor's search command or as powerful as a full text processing language. This book shows you the many ways regular expressions can increase your productivity. It teaches you how to think regular expressions so that you can master them, taking advantage of the full magnitude of their power. A full program that solves the doubled-word problem can be implemented in just a few lines of many of today's popular languages. With a single regular-expression search-and-replace command, you can find and highlight doubled words in the document. With another, you can remove all lines without doubled words (leaving only the lines of interest left to report). Finally, with a third, you can ensure that each line to be displayed begins with the name of the file the line came from. We'll see examples in Perl and Java in the next chapter. The host language (Perl, Java, VB.NET, or whatever) provides the peripheral processing support, but the real power comes from regular expressions. In harnessing this power for your own needs, you learn how to write regular expressions to identify text you want, while bypassing text you don't. You can then combine your expressions with the language's support constructs to actually do something with the text (add appropriate highlighting codes, remove the text, change the text, and so on).

python异常处理与调试,正则表达式

####异常处理与调试#### 1.cacl包里没加if __name__ == "__main__":时,hell.py在调用mun中的方法时,会执行mun中的print,加了之后则没有。 2....
  • Adhuyanchong
  • Adhuyanchong
  • 2017年07月17日 16:42
  • 176

如何使用鲁大师进行驱动备份

装过系统的同学都知道,如果装系统
  • u013018721
  • u013018721
  • 2014年07月01日 21:14
  • 677

【漫游大师6.0】漫游大师快速入门

一、实验准备 二、制作步骤 三、实验
  • liyongliang_2012
  • liyongliang_2012
  • 2014年05月13日 16:43
  • 2199

蜘蛛大师真的可以加快网站收录吗

现在的很多站长最揪心的就是站点不收录,或者是收录太少,收录直接关系着排名,没有收录何来排名。但随着百度算法的不断更新,百度对于收录的准则也越来越高。怎么将站点的收录做好成了大批站长需要解决的问题,很多...
  • sinat_35621539
  • sinat_35621539
  • 2016年12月26日 14:46
  • 801

LINUX start_kernel 分析,一位大师级的人物写的,不看要后悔的哟!!

start_kernel 分析 2013-04-16 17:29:41 分类: LINUX 一位大师级的人物写的,不看要后悔的哟!! 如果以为到了c代码可以松一口气的话,...
  • hktkfly6
  • hktkfly6
  • 2014年05月08日 10:43
  • 475

邮箱大师添加outlook2010 方法 图文详解

原文链接:http://blog.csdn.net/baidu_33740240/article/details/51086351 1.手机打开邮箱大师,添加邮箱账号,输入已有的outlook邮箱账号...
  • baidu_33740240
  • baidu_33740240
  • 2016年04月07日 15:28
  • 3690

2015年Android作品集

南周知道 要严肃,有知识;要八卦,有内幕。每天一篇,尽享你想知道的和不知道的,我们只想,让知道成为一种享受。请记住知道,南方周末每日网络专稿。 1.每天推送一篇你想知道的 2.来这里说...
  • wwj_748
  • wwj_748
  • 2016年02月23日 14:59
  • 6894

《3d游戏编程大师技巧》笔记

最近沉迷游戏实在颓废,╮(╯▽╰)╭。 王者荣耀已经上网者了,从今天开始杜绝此类易沉迷游戏!!! 书看了就忘,不过我肯定至少会看两遍的。 1、 //这个函数通过REST_BIT来清除object状...
  • skillart
  • skillart
  • 2016年09月29日 01:22
  • 1231

讲课大师 如何更新讲课接口

收到手机的小伙伴们,请保留以下几个软件,删除后将不能使用讲课大师的功能了。 1. Xposed Installer:相当于苹果手机的越狱。 2. SuperSu: 管理ROOT授权。 3. ...
  • qq_25146921
  • qq_25146921
  • 2017年06月26日 17:02
  • 757

分享两款表单大师——专业的表单设计和数据收集管理平台

表单大师,专注于对网站提供表单设计和数据的收集与管理服务,解决市场人员的用户资源管理问题,从录入商机用户到后期的跟踪管理、二次营销,表单大师用一流的技术团队实施全程护驾,帮助互联网创业者精准化管理用户...
  • English0523
  • English0523
  • 2016年07月12日 09:52
  • 45224
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:来自正则表达式大师的作品
举报原因:
原因补充:

(最多只允许输入30个字)