首页
\
问答
\
如何从jmeter响应中提取正则表达式提取器?(how to extract Regular expression extractor from jmeter response?)
如何从jmeter响应中提取正则表达式提取器?(how to extract Regular expression extractor from jmeter response?)
ChemicalID=265297\u0026RptId=46160
。这是我的jmeter请求响应中的文本。 有人可以帮助我如何编写正则表达式从上述响应中提取
265297
?
ChemicalID=265297\u0026RptId=46160
.This is a text from my jmeter request response. Can somebody help me how to write regular expression to extract
265297
from the above response?
原文:https://stackoverflow.com/questions/43222917
更新时间:2023-08-05 16:08
最满意答案
该匹配的范围是grep
{}
代码块。 您可以改为使用for
循环:use warnings; use strict; my $fields_dump = [ { 'DEFAULT_FIELD_LABEL' => 'telco_hier_building', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'building', }, { 'DEFAULT_FIELD_LABEL' => 'Request Type', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'request_type', }, { 'DEFAULT_FIELD_LABEL' => 'Request Completion Date', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'request_completion_date', }, ]; for (@{ $fields_dump }) { if ($_->{DEFAULT_FIELD_LABEL} =~ m/(telco_hier_|telco_imac_)building/) { my $telco_prefix = $1; print "$telco_prefix\n"; } }
输出是:
telco_hier_
在perldoc perlvar进一步解释。
The match is scoped to the grep
{}
code block. You can use afor
loop instead:use warnings; use strict; my $fields_dump = [ { 'DEFAULT_FIELD_LABEL' => 'telco_hier_building', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'building', }, { 'DEFAULT_FIELD_LABEL' => 'Request Type', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'request_type', }, { 'DEFAULT_FIELD_LABEL' => 'Request Completion Date', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => 'request_completion_date', }, ]; for (@{ $fields_dump }) { if ($_->{DEFAULT_FIELD_LABEL} =~ m/(telco_hier_|telco_imac_)building/) { my $telco_prefix = $1; print "$telco_prefix\n"; } }
Output is:
telco_hier_
Further explanation in perldoc perlvar.
相关问答
更多-
正则表达式有条件的前瞻与下一个捕获组匹配PCRE(Regular Expression conditional lookahead with next capture group match PCRE)[2023-02-05]
你的模式包含(?(?=ls)yes|no) ,这是字面上预测字符ls 。 我已经改变了你的模式以利用DEFINE结构来实现子模式的可重用性。 据我所知,PCRE没有一种方法来检查在条件之后是否定义了一个组。 这可以使用平衡组在.net中完成,但PCRE不采用这些方法。 PCRE确实有条件的(?(name)yes|no)或(?(1)yes|no) ,但它对于前向引用不起作用(相对于在甚至声明前是否存在变量)。 请参阅这里使用的正则表达式 (?(DEFINE) (?# var ) (?[a-z ... -
使用分支重置组 (?|.....)将多个捕获转换为单个捕获。 (?|\[([^\]]*)\]|\{([^\}]*)\}) 也就是说,分支重置组内的备选方案共享相同的捕获组。 DEMO Use the branch reset group (?|.....) to turn multiple captures into a single one. (?|\[([^\]]*)\]|\{([^\}]*)\}) That is, alternatives inside a branch reset group ...
-
-
正则表达式捕获组很快(Regex capture group swift)[2022-08-03]
NSTextCheckingResult有一个numberOfRanges属性和一个rangeAtIndex()方法,可以让您获取各个捕获组的范围。 因此,如果您想要第一个捕获组而不是整个匹配的字符串,则可以将您的代码修改为: var matches : Array= Array () regex.enumerateMatchesInString(self, options: NSMatchingOptions(rawValue: 0), ra ... -
你的第一个错误是\w的错误解释。 这是javadoc说的: \w A word character: [a-zA-Z_0-9] 这意味着\w可以捕获字母和数字。 所以,在你的情况下,考虑到字母总是大写,我会使用以下模式: [AZ]\d+ 现在它将捕获第一名的标记。 所以你应该自己实现这个循环: Pattern p = Pattern.compile("([A-Z]\\d+)"); Matcher m = p.matcher(str); while (m.find()) { String place ...
-
该匹配的范围是grep {}代码块。 您可以改为使用for循环: use warnings; use strict; my $fields_dump = [ { 'DEFAULT_FIELD_LABEL' => 'telco_hier_building', 'APPROVER_ORDER' => '0', 'IS_READONLY' => '0', 'FORM_ID' => '3913', 'REFERENCE' => ...
-
捕获正则表达式中的重复组(capture a repeating group in regex)[2023-04-23]
看起来你正在使用std::regex_match 你可以使用std::regex_search或std::regex_iterator做你想要的(用正则表达式([^_]+) ) it seems like you are using std::regex_match you can use std::regex_search or std::regex_iterator to do what you want (with regex ([^_]+)) -
我如何通过Regex捕获单词(How can I capture word by Regex)[2023-11-14]
要提取任意数量的键并反转结果数组中元素的顺序: str = "message[0][generic][0][elements][0][default_action][url]"; res = str.match(/\[([^\d\]]+)\](?=\[[^\d\]]*\]|$)/g) .map(function(s) { return s.replace(/[\[\]]/g, "") }) .reverse(); console.log(res); To extract any number ... -
正则表达式量化捕获(Regex quantified capture)[2021-10-21]
试试这个: preg_match_all("@(?:/m)?/([^/]+)(?:/t)?@", "/m/part/other-part/another-part/t", $m); var_dump($m); 它给: array(2) { [0]=> array(3) { [0]=> string(7) "/m/part" [1]=> string(11) "/other-part" [2]=> string(15) "/another-part/t ... -
transform_keys不会就地运行,并且each返回原始迭代器,而不是块的结果。 你可以用map而不是each map做你想做的事。 def strip s = array_of_hashes.map { |hash| hash.transform_keys { |key| key.sub(/^a_(\d+)_/, '') } } end 或者,您可以使用transform_keys! 修改array_of_hashes的内容 def strip s = array_of ...