dongshen3352
2017-07-27 19:15
浏览 48
已采纳

regexp.FindAll *的最大行长?

Is there a maximum length defined for text lines fed to the regexp.FindAll*Index() functions in the regexp package? Running the code below only provides the indices of the last 10 occurrences.

Go 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))
}

Yields:

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

I've tried several of the FindAll*Index funcs and they're all the same.

图片转代码服务由CSDN问答提供 功能建议

是否存在为馈给 regexp.FindAll * Index()的文本行定义的最大长度</ </ code> regexp包中的函数? 运行下面的代码仅提供最近10次出现的索引。</ p>

去游乐场: https://play.golang.org/p/QgOw7TzuV4 </ p>

 程序包main 
 
import(
“ fmt” 
”  regexp“ 
)
 
func main(){
 line:=`VAL_ Status 31” 31-不可用“ 30” 30-未定义“ 29” 29-未定义“ 28” 28-接收到的温度信息“  27“ 27温度主(子系统)” 26“ 26节气门不相关” 25“ 25节气门位置信息” 24“ 24节气门位置” 23“ 23节气门位置” 22“ 22节气门 主(子系统)“ 21” 21油补充泵压力“ 20” 20发动机/ B平均速度“ 19” 19-A / D功率调节器“ 18” 18接收的油温“ 17” 17油 主要温度(IA)“ 16” 16-B-平均速度“ 15” 15冲程位置零“ 14” 14油门主要(RVDT)“ 13” 13发动机速度“ 12” 12换档选择临界“  11“ 11档模式非严重故障” 10“ 10输出驱动器” 9“ 9看门狗关闭”  8“ 8转向电磁阀” 7“ 7车辆驾驶ID5” 6“ 6车辆驾驶ID4” 5“ 5车辆驾驶ID3” 4“ 4车辆驾驶ID2” 3“ 3车辆驾驶ID1” 2“  2系统电源“ 1” 1-ROM“ 0” 0-未检测到故障“;`
 re:= regexp.MustCompile(” [0-9]“)
 
 fmt.Println(re.FindAllStringIndex( 行,-1))
} 
 </ code> </ pre> 
 
 

收益:</ p>

[[677 680] [696699 ] [722 725] [753 756] [784 787] [815 818] [846 849] [877 880] [896 899] [906 909]] </ code> </ p>

I 已经尝试了几种FindAll * Index函数,它们都是相同的。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题