来自正则表达式大师的作品
来源:互联网 发布:winhex数据恢复分区 编辑:程序博客网 时间:2024/04/29 21:57
Introduction to Regular ExpressionsHere'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).
- 来自正则表达式大师的作品
- 正则表达式,来自百度百科
- Scala 第十五讲 正则表达式 从大数据菜鸟走上大师的历程
- 解读 C# 中的正则表达式[来自网上]
- 正则表达式 Java(来自百度知道)
- 正则表达式-来自百度百科
- javascript中的正则表达式(来自W3C)
- matlab__正则表达式(部分来自转载)
- 大师来自巧匠
- 一副好的平面设计作品,来自优秀的字体
- 来自CSDN的作品,对我会有帮助
- 60佳灵感来自大自然的网页设计作品欣赏
- 25个灵感来自大自然的优秀网站设计作品
- 60佳灵感来自大自然的网页设计作品欣赏
- Lua正则表达式(精简而不失大师风范)
- CocoaChina 允许iOS开发者相互推广自己的作品,发码大师相当不错!
- 大师大师搭讪的
- 正则表达式---常用的正则
- http://blog.csdn.net/foxmail/archive/2004/06/25/26418.aspx
- 我的自白
- spring第一个程序笔记
- [转自 拼搏之路] 如何翻译中文地址
- 我对servlet配置文件的理解
- 来自正则表达式大师的作品
- 介绍微软一个罕为人知的无敌命令(转贴)
- JScript.Net 之 SqlDataReader读取数据
- ASP与ASP.NET在COOKIE方面的区别
- JavaScript 经典自定义函数[转帖]
- 魔鬼城--雅丹地貌
- 双硬盘的安装
- 东汉魏晋南北朝时期职业教徒的阶层分析
- vc++学习笔记(五)