Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1745596
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Python/Ruby

2011-08-22 20:56:45

7.7. Summary

This is just the tiniest tip of the iceberg of what regular expressions can do. In other words, even though you're completely overwhelmed by them now, believe me, you ain't seen nothing yet

这只是正则表达式所能做事的冰山一角中很小一部分。换句话说,即使你现在完全的掌握了正则表达式,相信我,你也是只是看到其中的一部分。

You should now be familiar with the following techniques:

你需要掌握下面的技术:

  • ^ matches the beginning of a string.
  • ^匹配字符串的开始
  • $ matches the end of a string.
  • $匹配字符的结束
  • \b matches a word boundary.
  • \b用来匹配单个单词
  • \d matches any numeric digit.
  • \d匹配任意的数字
  • \D matches any non-numeric character.
  • \D 匹配任意的非数字字符
  • x? matches an optional x character (in other words, it matches an x zero or one times).
  • X?匹配一个可选的字符X(换句话说,它可以匹配01个字符x
  • x* matches x zero or more times.
  • X*匹配任意个字符x
  • x+ matches x one or more times.
  • X+匹配 一个或多个字符x
  • x{n,m} matches an x character at least n times, but not more than m times.
  • X{n,m}匹配的是至少含有字符x至少出现n次,但是最多不能超过m
  • (a|b|c) matches either a or b or c.
  • a|b|c)匹配a,b,c中的一个,只能匹配其中的一个
  • (x) in general is remembered group. You can get the value of what matched by using
  • (x)通常是一个被记忆的组,通过使用它,你可以获取匹配的字符的值
  • groups() method of the object returned by re.search.
  • re.search返回的对象包含e,groups()方法

Regular expressions are extremely powerful, but they are not the correct solution for every problem. You should learn enough about them to know when they are appropriate, when they will solve your problems, and when they will cause more problems than they solve.

正则表达式是很强大的,但是它并不是所有问题都能解决。你必须清楚的知道何时使用正则表达式,如正则表达式是否能解决你的问题时或是它引起的问题远比它们解决的问题严重。

 

Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.

当有些人面对一个问题时,他们可能会想到:我知道,我要使用正则表达式“。现在他们有两个毛病了。

阅读(929) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~