Flag | 含义 |
---|---|
i | 不区分大小写 |
s | 让.匹配\n(单行模式) |
m | 除了开始/结束文本外,让^并$匹配开始/结束行(多行模式) |
用法
例如:前缀"(?is)"使匹配的字符不区分大小写,并让. 匹配 \n
package main
import (
"fmt"
"regexp"
)
const CONTENT = `<div class="info">
<div class="hd">
<a href="https://movie.douban.com/subject/1291546/" class="">
<span class="title">霸王别姬</span>
<span class="other"> / 再见,我的妾 / Farewell My Concubine</span>
</a>
`
func main() {
a := regexp.MustCompile(`(?is:class.*?</span>)`)
fmt.Println(a)
fmt.Println(a.FindAllString(CONTENT, -1))
}
输出:
(?is:class.*?</span>)
[class="info"> <div class="hd"> <a href="https://movie.douban.com/subject/1291546/" class=""> <span class="title">霸王别姬</span> class="other"> / 再见,我的妾 / Farewell My Concubine</span>]