Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用svlib在systemverilog中处理正则表达式_Regex_Posix_System Verilog - Fatal编程技术网

Regex 使用svlib在systemverilog中处理正则表达式

Regex 使用svlib在systemverilog中处理正则表达式,regex,posix,system-verilog,Regex,Posix,System Verilog,我是systemverilog环境中svlib包的新用户。提到我有以下示例文本,{'PARAMATER':'lollg_1','SPEC_ID':'1G3HSB_1'},我想使用正则表达式从这个文本中提取1G3HSB 出于这个原因,我使用下面的代码片段,但我得到的是整行代码,而不仅仅是信息 wordsRe = regex_match(words[i], "\'SPEC_ID\': \'(.*?)\'"); $display("This is the output o

我是systemverilog环境中svlib包的新用户。提到我有以下示例文本,{'PARAMATER':'lollg_1','SPEC_ID':'1G3HSB_1'},我想使用正则表达式从这个文本中提取1G3HSB

出于这个原因,我使用下面的代码片段,但我得到的是整行代码,而不仅仅是信息

wordsRe = regex_match(words[i], "\'SPEC_ID\': \'(.*?)\'");
$display("This is the output of Regex: %s", wordsRe.getStrContents())
谁能告诉我出了什么问题吗? 我得到的输出:{'PARAMATER':'lollg_1','SPEC_ID':'1G3HSB_1'}
而且,我想得到:1G3HSB_1

似乎您需要使用
getMatchString(1)
获得第一个捕获组的内容。此外,您需要使用贪婪量词(懒惰量词不符合POSIX)和反括号表达式-
[^']*
而不是
*?

wordsRe = regex_match(words[i], "\'SPEC_ID\': \'([^\']*)\'");
$display("This is the output of Regex: %s", wordsRe.getMatchString(1))
有关详细信息,请参阅用户指南:

getMatchString(m)
始终完全等同于对包含搜索字符串的Str对象调用range方法:

range(getMatchStart(m), getMatchLength(m))

就这么做了顺便说一句,你能解释一下原因吗?不会工作,[^']*会吗?提前感谢。POSIX正则表达式不支持惰性量词。要在两个字符之间匹配尽可能少的字符,需要使用反括号表达式/字符类。