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.

  • 写回答

1条回答 默认 最新

  • dongroufan6846 2017-07-27 19:19
    关注

    There is no real limit on the number of matches. The reason your regex is not getting more matches is because it needs to be regexp.MustCompile(" [0-9]+ ") to match numbers with more than one digit, surrounded by spaces. Right now it only matches " 0 " through to " 9 ".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制