regexp.FindAll *的最大行长度?

时间:2017-07-27 19:15:35

标签: go

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

去游乐场: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功能,但它们都是一样的。

1 个答案:

答案 0 :(得分:4)

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