您可以使用正则表达式来拆分字符串 'K89+050-K90+210右侧路堑挡墙'。

在Go中,您可以使用 regexp 包来处理正则表达式。以下是一个示例代码,演示如何将字符串拆分为 'K89+050-K90+210' 和 '右侧路堑挡墙'。

package main

import (
	"fmt"
	"regexp"
)

func main() {
	str := "K89+050-K90+210右侧路堑挡墙"
	re := regexp.MustCompile(`^(.+)右侧路堑挡墙$`)
	match := re.FindStringSubmatch(str)
	if len(match) >= 2 {
		fmt.Println("拆分结果:")
		fmt.Println(match[1]) // "K89+050-K90+210"
		fmt.Println("右侧路堑挡墙")
	} else {
		fmt.Println("未找到匹配")
	}
}

上述代码中的正则表达式 ^(.+)右侧路堑挡墙$ 匹配以任意字符开头,然后是字符串 '右侧路堑挡墙' 结尾的部分。使用 FindStringSubmatch 函数可以找到匹配的子字符串。如果找到匹配,则结果的第一个元素(索引为1)将是 'K89+050-K90+210'。


原文地址: https://www.cveoy.top/t/topic/p4O8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录