Browse files

Update 01-chapter1.markdown

  • Loading branch information...
gingerhot committed Dec 19, 2013
1 parent 5314c8f commit 45ec9c77799769848b4e442079be30f0f46dfd5e
Showing with 5 additions and 9 deletions.
  1. +5 −9 01-chapter1.markdown
@@ -2,7 +2,7 @@
## 简单匹配 ##
-你想知道一个字符串和一个正则表达式是否匹配,*MatchString*-函数 returns 'true' if the string-argument matches the regular expression that you prepared with *Compile*.
+你想知道一个字符串和一个正则表达式是否匹配,如果字符串参数与用 *Compile* 函数处理好的正则匹配的话,*MatchString* 函数就会返回 'true'.
package main
@@ -27,12 +27,8 @@
-*Compile* is the heart of the regexp-package. Every regular expression must be prepared with *Compile* or
-its sister-function *MustCompile*. The *MustCompile*-function behaves
-almost like *Compile*, but throws a panic if the regular expression cannot be compiled. Because any
-error in *MustCompile* leads to a panic, there is no need for returning an error code as second return value.
-This makes it easier to chain the *MustCompile* call with the match-function of your choice, like shown here:
-(But you should avoid the repeated compilation of a regular expression in a loop for performance reasons.)
+*Compile* regexp 包的核心所在。 每一个正则必由 *Compile* 或其姊妹函数 *MustCompile* 处理后方可使用。*MustCompile* 除了正则在不能正确被编译时会抛出异常外,使用方法和 *Compile* 几乎相同。因为 *MustCompile* 的任何错误都会导致一个异常,所以它无需返回第二个表示错误码的返回值。这就使得把 *MustCompile* 调用和匹配函数链在一起更加容易。像下面这样:
package main
@@ -50,11 +46,11 @@ This makes it easier to chain the *MustCompile* call with the match-function of
-The following illegal regexp
var myre = regexp.MustCompile(`\d(+`)
-will yield
panic: regexp: Compile(`\d(+`): error parsing regexp: missing argument to repetition operator: `+`

0 comments on commit 45ec9c7

Please sign in to comment.