gpt4 book ai didi

go - regexp.FindAll* 的最大行长度?

转载 作者:IT王子 更新时间:2023-10-29 02:29:11 26 4
gpt4 key购买 nike

是否为 regexp 包中的 regexp.FindAll*Index() 函数定义了文本行的最大长度?运行下面的代码只提供最近 10 次出现的索引。

去 Playground :https://play.golang.org/p/QgOw7TzuV4

package main

import (
"fmt"
"regexp"
)

func main() {
line := `VAL_ Status 31 "31-Not Available" 30 "30-Not Defined" 29 "29-Not Defined" 28 "28-Received Temperature Msg" 27 "27 Temp Main (Sub-system)" 26 "26-Throttle Out of Correlation" 25 "25-Received Throttle Pos Msg" 24 "24-Received Throttle Position" 23 "23-Pedal Throttle Position" 22 "22-Throtttle Main (Sub-System)" 21 "21-Oil Makeup Pump Pressure" 20 "20-Engine/B-Average Speeds" 19 "19-A/D Power Regulator" 18 "18-Received Oil Temperature" 17 "17-Oil Temperature Main (IA)" 16 "16-B-Average Speed" 15 "15-Zero Stroke Position" 14 "14-Throttle Main (RVDT)" 13 "13-Engine Speed" 12 "12-Shift Mode Sel-Critical" 11 "11-Shift Mode Sel-Non Critical" 10 "10-Output Driver" 9 "9-Watchdog Off" 8 "8-Steer Gain Solenoid" 7 "7-Vehicle Driveability ID5" 6 "6-Vehicle Driveability ID4" 5 "5-Vehicle Driveability ID3" 4 "4-Vehicle Driveability ID2" 3 "3-Vehicle Driveability ID1" 2 "2-System Power" 1 "1-ROM" 0 "0-No Failures Detected" ;`
re := regexp.MustCompile(" [0-9] ")

fmt.Println(re.FindAllStringIndex(line, -1))
}

产量:

[[677 680] [696 699] [722 725] [753 756] [784 787] [815 818] [846 849] [877 880] [896 899] [906 909]]

我已经尝试了几个 FindAll*Index 函数,它们都是一样的。

最佳答案

比赛的数量没有真正的限制。您的正则表达式没有获得更多匹配项的原因是因为它需要 regexp.MustCompile("[0-9]+ ") 来匹配超过一位数字的数字,并用空格包围。现在它只匹配 "0 ""9 "

关于go - regexp.FindAll* 的最大行长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45359250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com