问题
I'm trying to extract a part of html in a jmeter test.
I need to extract just a part from a <script src=""
tag.
full script src:
<script src="/Paginas/Inicializacao/AguardarAcao.aspx?_TSM_HiddenField_=ctl00_ToolkitScriptManager1_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d1.0.11119.38311%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3apt-BR%3adf9c6e46-ef8c-4a3d-89af-f80adf22e9c2%3a865923e8%3a411fea1c%3ae7c87f07%3a91bd373d%3a1d58b08c%3a8e72a662%3aacd642d2%3a596d588c%3a77c58d20%3a14b56adc%3a269a19ae" type="text/javascript"></script>
and I need just:
%3b%3bAjaxControlToolkit%2c+Version%3d1.0.11119.38311%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3apt-BR%3adf9c6e46-ef8c-4a3d-89af-f80adf22e9c2%3a865923e8%3a411fea1c%3ae7c87f07%3a91bd373d%3a1d58b08c%3a8e72a662%3aacd642d2%3a596d588c%3a77c58d20%3a14b56adc%3a269a19ae
Right now I created this regex:
%3b.*"
that matches:
%3b%3bAjaxControlToolkit%2c+Version%3d1.0.11119.38311%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3apt-BR%3adf9c6e46-ef8c-4a3d-89af-f80adf22e9c2%3a865923e8%3a411fea1c%3ae7c87f07%3a91bd373d%3a1d58b08c%3a8e72a662%3aacd642d2%3a596d588c%3a77c58d20%3a14b56adc%3a269a19ae"
But I don't want the last two chars (one white space) and the "
.
How to remove this last two chars?
回答1:
Use regular expression pattern
%[^"]+
回答2:
Maybe a positive look-ahead could help, something like:
%3b.*(?="\s)
回答3:
^(.*).{1}
works really well
the ^ denotes the start of the line, the (.*) captures any number of characters and the .{1} removes the last character from the string
for example:
Input: 100.00%
Output 100.00
来源:https://stackoverflow.com/questions/20358071/remove-last-char-from-result-of-a-match-regex