diff --git a/en/07.3.md b/en/07.3.md
index 949c71f4..704347cf 100644
--- a/en/07.3.md
+++ b/en/07.3.md
@@ -11,33 +11,33 @@ If you recall form validation from previous sections, we used Regexp to verify t
The `regexp` package has 3 functions to match: if it matches a pattern, then it returns true, returning false otherwise.
```Go
- func Match(pattern string, b []byte) (matched bool, error error)
- func MatchReader(pattern string, r io.RuneReader) (matched bool, error error)
- func MatchString(pattern string, s string) (matched bool, error error)
+func Match(pattern string, b []byte) (matched bool, error error)
+func MatchReader(pattern string, r io.RuneReader) (matched bool, error error)
+func MatchString(pattern string, s string) (matched bool, error error)
```
All 3 functions check if `pattern` matches the input source, returning true if it matches. However if your Regex has syntax errors, it will return an error. The 3 input sources of these functions are `slice of byte`, `RuneReader` and `string`.
Here is an example of how to verify an IP address:
```Go
- func IsIP(ip string) (b bool) {
- if m, _ := regexp.MatchString("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", ip); !m {
- return false
- }
- return true
+func IsIP(ip string) (b bool) {
+ if m, _ := regexp.MatchString("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", ip); !m {
+ return false
}
+ return true
+}
```
As you can see, using pattern in the `regexp` package is not that different. Here's one more example on verifying whether user input is valid:
```Go
- func main() {
- if len(os.Args) == 1 {
- fmt.Println("Usage: regexp [string]")
- os.Exit(1)
- } else if m, _ := regexp.MatchString("^[0-9]+$", os.Args[1]); m {
- fmt.Println("Number")
- } else {
- fmt.Println("Not number")
- }
+func main() {
+ if len(os.Args) == 1 {
+ fmt.Println("Usage: regexp [string]")
+ os.Exit(1)
+ } else if m, _ := regexp.MatchString("^[0-9]+$", os.Args[1]); m {
+ fmt.Println("Number")
+ } else {
+ fmt.Println("Not number")
}
+}
```
In the above examples, we use `Match(Reader|String)` to check if content is valid, but they are all easy to use.
@@ -47,189 +47,189 @@ Match mode can verify content but it cannot cut, filter or collect data from it.
Let's say we need to write a crawler. Here is an example for when you must use Regexp to filter and cut data.
```Go
- package main
+package main
- import (
- "fmt"
- "io/ioutil"
- "net/http"
- "regexp"
- "strings"
- )
+import (
+ "fmt"
+ "io/ioutil"
+ "net/http"
+ "regexp"
+ "strings"
+)
- func main() {
- resp, err := http.Get("http://www.baidu.com")
- if err != nil {
- fmt.Println("http get error.")
- }
- defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("http read error")
- return
- }
-
- src := string(body)
-
- // Convert HTML tags to lower case.
- re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
- src = re.ReplaceAllStringFunc(src, strings.ToLower)
-
- // Remove STYLE.
- re, _ = regexp.Compile("\\")
+ src = re.ReplaceAllString(src, "")
+
+ // Remove SCRIPT.
+ re, _ = regexp.Compile("\\