I use the regexp expression to get the data from .xlsx file. but i am poor and a newer in regexp. Anyone could help me?
package main
import (
"fmt"
"regexp"
)
func main() {
input := `
<sheetData>
<row r="2" spans="1:15">
<c r="A2" s="5" ><v>{{range .txt}}</v></c>
<c r="B2" s="5" t="s"><v>1</v></c>
<c r="C2" s="5" t="s"><v>2</v></c>
<c r="D2" s="5" t="s"><v>3</v></c>
<c r="E2" s="5" />
<c r="K2" s="6" t="s"><v>21</v></c>
</row>
<row r="3" spans="1:15">
<c r="A3" s="5" t="s"><v>0</v></c>
<c r="B3" s="5" t="s"><v>1</v></c>
<c r="C3" s="5" t="s"><v>2</v></c>
<c r="D3" s="5" t="s"><v>3</v></c>
<c r="E3" s="5" />
<c r="K3" s="6" t="s"><v>21</v></c>
</row>
</sheetData>`
r := regexp.MustCompile(`<row[^>]*?r="(\d+)"[^>].*?>.*?[(<v>(.*?)<\/v>.*?)]<\/row>`)
r2 := regexp.MustCompile(`<v>(.*?)</v>`)
row:=r.FindAllString(input,-1)
for _,v:=range row {
fmt.Println(r.ReplaceAllStringFunc(v, func(m string) string {
match:=r2.FindAllString(v,-1)
for kk,vv:=range match {
fmt.Println(kk,vv)
fmt.Println(r2.ReplaceAllString(v, ""))
}
}))
}
}
Question:
How to get the string {{range .txt}} ,and throw off the tag"..."
How to get the "3" from
r="3"
,and get the "A3,B3,C3..." from the "
Thanks in advance!