Discussion:
Regular Expression
Puneet Varma
2018-09-17 15:33:39 UTC
Permalink
I have used the following regular expression for the value
2C94854D656354990165E824FA460175 with the regular expression
value="(.+?)" />

it is not working. it is a check box, Id changes every time I am running
it.

Any help is greatly appreciate it.
Deepak Shetty
2018-09-17 16:50:43 UTC
Permalink
Hi
you havent posted the text you are matching against so cant say why your
regex isnt working
Generally expressions like the above fail because . You have whitespace ,
or you are using a single quote or there is something between value and the
end of your tag like a css class and so on. Check the text of the response
and ensure that your regex is a child of the sampler returning the response

regards
deepak
Post by Puneet Varma
I have used the following regular expression for the value
2C94854D656354990165E824FA460175 with the regular expression
value="(.+?)" />
it is not working. it is a check box, Id changes every time I am running
it.
Any help is greatly appreciate it.
Puneet Varma
2018-09-17 17:05:07 UTC
Permalink
Thanks for the response. Below is what I have for the checkbox.


<input id="sg:cf:b:0" type="checkbox" name="sg:cf:b" checked="checked"
value="2C94854D656354990165E824FA460175" int-ns-multiple="sgcfb">
Post by Deepak Shetty
Hi
you havent posted the text you are matching against so cant say why your
regex isnt working
Generally expressions like the above fail because . You have whitespace ,
or you are using a single quote or there is something between value and the
end of your tag like a css class and so on. Check the text of the response
and ensure that your regex is a child of the sampler returning the response
regards
deepak
Post by Puneet Varma
I have used the following regular expression for the value
2C94854D656354990165E824FA460175 with the regular expression
value="(.+?)" />
it is not working. it is a check box, Id changes every time I am running
it.
Any help is greatly appreciate it.
Deepak Shetty
2018-09-17 17:14:57 UTC
Permalink
Hi
name=" sg:cf:b"\s+checked="checked"\s+value="([^"]+)" should work - The
reason you have to add the name is because there are likely other html
elements. Its upto you if you want to retain the checked part (will break
whenever your html changes slightly) v/s a more generic .+? which is
inefficient. If you are willing to give up some efficiency and memory ,the
XPath selectors usually work better for HTML elements (in the sense of
easier to read and logical in how they deal with attributes)

Your original expression had /> which is not in your text , so it would
not have worked (As well as you are likely to have matched some other value.


regards
deepak
Post by Puneet Varma
Thanks for the response. Below is what I have for the checkbox.
<input id="sg:cf:b:0" type="checkbox" name="sg:cf:b" checked="checked"
value="2C94854D656354990165E824FA460175" int-ns-multiple="sgcfb">
Post by Deepak Shetty
Hi
you havent posted the text you are matching against so cant say why your
regex isnt working
Generally expressions like the above fail because . You have whitespace ,
or you are using a single quote or there is something between value and
the
Post by Deepak Shetty
end of your tag like a css class and so on. Check the text of the
response
Post by Deepak Shetty
and ensure that your regex is a child of the sampler returning the
response
Post by Deepak Shetty
regards
deepak
Post by Puneet Varma
I have used the following regular expression for the value
2C94854D656354990165E824FA460175 with the regular expression
value="(.+?)" />
it is not working. it is a check box, Id changes every time I am
running
Post by Deepak Shetty
Post by Puneet Varma
it.
Any help is greatly appreciate it.
g***@live.com
2018-09-20 14:45:56 UTC
Permalink
Mind that using Regular Expressions for HTML response types might be not the
best idea <https://stackoverflow.com/a/1732454/2897748> as regular
expressions are hard to develop/maintain/understand, they are fragile, they
are sensitive to markup changes (i.e. if order of attributes changes or
there will be a line break - it will run your regex).

So consider going for CSS/JQuery Extractor
<http://jmeter.apache.org/usermanual/component_reference.html#CSS/JQuery_Extractor>
instead, the configuration would be as simple as:

CSS Selection Expression:* input[id=sg:cf:b:0]*
Attribute: *value*

Demo:

<Loading Image...>

More information: How to Use the CSS/JQuery Extractor in JMeter
<https://www.blazemeter.com/blog/how-use-cssjquery-extractor-jmeter>



--
Sent from: http://www.jmeter-archive.org/JMeter-User-f512775.html

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@jmeter.apache.org
For additional commands, e-mail: user-***@jmeter.apache.org

Continue reading on narkive:
Loading...