Compare commits

..

No commits in common. "main" and "v1.2.2" have entirely different histories.
main ... v1.2.2

1 changed files with 1 additions and 18 deletions

View File

@ -6,7 +6,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
) )
@ -269,30 +268,14 @@ func CleanString(str string) string {
if IsComment(str) { if IsComment(str) {
return "" return ""
} }
result := getAccountWithNumber(str)
// 去除 " ", ";", "\r" // 去除 " ", ";", "\r"
result = strings.ReplaceAll(result, ",", "") result := strings.ReplaceAll(str, ",", "")
result = strings.ReplaceAll(result, " ", "") result = strings.ReplaceAll(result, " ", "")
// 过滤空白的商户信息 ““
result = strings.ReplaceAll(result, "\"\"", "")
result = strings.ReplaceAll(result, ";", "") result = strings.ReplaceAll(result, ";", "")
result = strings.ReplaceAll(result, "\r", "") result = strings.ReplaceAll(result, "\r", "")
// 清楚汇率转换
return result return result
} }
// 正则提取:
// Assets:Flow:Cash:现金 -20.00 USD {xxx CNY, 2025-01-01} -> Assets:Flow:Cash:现金 -20.00 USD
func getAccountWithNumber(str string) string {
// 定义正则表达式模式
pattern := `^[^\{]+`
// 编译正则表达式
re := regexp.MustCompile(pattern)
// 使用正则提取匹配的部分
return re.FindString(str)
}
func IsComment(line string) bool { func IsComment(line string) bool {
trimmed := strings.TrimLeft(line, " ") trimmed := strings.TrimLeft(line, " ")
if strings.HasPrefix(trimmed, ";") { if strings.HasPrefix(trimmed, ";") {