使用 svlib 在 systemverilog 中处理正则表达式
Regex processing in systemverilog using svlib
我是 systemverilog 环境中 svlib 包的新用户。参考Verilab 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)
is always exactly equivalent to calling the range method on the Str object containing the string that was searched:
range(getMatchStart(m), getMatchLength(m))
我是 systemverilog 环境中 svlib 包的新用户。参考Verilab 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)
is always exactly equivalent to calling the range method on the Str object containing the string that was searched:range(getMatchStart(m), getMatchLength(m))