- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
是否为 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/
我对这里的区别是什么以及为什么一个有效而另一个无效感到困惑。谁能解释一下? //The string to search through var str = "This is a string /*
我很困惑这里有什么区别以及为什么一个有效而另一个无效。有人能解释一下吗? //The string to search through var str = "This is a string /* w
概述 RegExp 的构造函数创建了一个正则表达式对象,用模式来匹配文本。 有关正则表达式介绍,请阅读JavaScript指南中的正则表达式章节。 语法 文字和构造符号是可能的: /patt
在我的数据库中,我有一个公司表。该表有一个名为 tags 的字段,其中包含以下内容: Furniture Retail E-commerce B2C Home & Furniture Consumer
var str='The_Andy_Griffith_Show'; // string to perform replace on var regExp1=/\s|[A-Z]/g; var reg
我正在为 VBA 编写一个脚本,用于 Outlook 2013,它使用正则表达式,我发现的每个示例似乎都使用 Set regex = New RegExp创建一个 RegExp 对象。当我尝试这个时,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
在“How do I removing URLs from text?”中建议使用以下代码: require 'uri' #... schemes_regex = /^(?:#{ URI.scheme
所以我有一个 RegExp regex =/asd/ 我将它作为 key 存储在我的键值对存储系统中。 所以我说 str = String(regex) 返回 "/asd/"。 现在我需要将该字符串转
谁能提供一些例子来解释 regexp.Compile 之间的区别?和 regexp.CompilePOSIX ?我阅读了文档。但是我无法得到直观的理解。 最佳答案 Perl 和 POSIX 兼容的正则
我目前正在学习 SQL 并使用 SSMS 2017。我不明白为什么在使用 REGEXP 语法时出现错误,它似乎适用于其他任何人: SELECT * FROM List WHERE Name REGEX
我有一个包含文本的 emacs 缓冲区 a1b2c3 使用正则表达式构建器,我创建了正则表达式 "b\\(2\\)" 并且可以看到匹配突出显示(b2,2 的颜色不同)。 但是,当我将表达式粘贴到 re
这个问题已经有答案了: JavaScript: using constructor without operator 'new' (2 个回答) 已关闭 7 年前。 RegExp('hi') 和有什么
我的正则表达式是这样的: ((?:[a-z][a-z0-9_]*)).*?(\d+).*?((?:[a-z][a-z0-9_]*)).*?(\d+).*?([a-z]) 如果我将其作为 MySQL R
我对基准测试和功能感兴趣?是否有理由使用 Jakarta 正则表达式? 最佳答案 似乎没有什么理由。但是除了 Jakarta 图书馆之外,还有其他一些有趣的图书馆。此链接提供了一些有关性能和 perl
如果声明了 SPEC Env,我将尝试有条件地加载我的测试: var context = null if (process.env.SPEC) { context = require.contex
我尝试为 emacs 编写一些新的对齐规则,但发现这种奇怪且不一致的行为。当前缓冲区内容: "some thing" like => this hello => world and => aga
这个问题在这里已经有了答案: Is gcc 4.8 or earlier buggy about regular expressions? (3 个答案) 关闭 8 年前。 我尝试使用 C++11
我遇到了两个错误,都与编码有关并且都相关。 我在启动 WEBrick 时遇到的第一个错误(技术上是警告): /Users/USERNAME/example/config/initializers/bb
我有一个 almost-json文件。估计1000 行。这是其中的一部分: level: { 1: { cost: 200,
我是一名优秀的程序员,十分优秀!