Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last char from result of a match regex

Tags:

regex

jmeter

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&amp;_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?

like image 934
Thiago Custodio Avatar asked Dec 03 '13 17:12

Thiago Custodio


People also ask

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.


2 Answers

Use regular expression pattern

%[^"]+
like image 106
Ωmega Avatar answered Oct 09 '22 10:10

Ωmega


Maybe a positive look-ahead could help, something like:

%3b.*(?="\s)
like image 32
svoop Avatar answered Oct 09 '22 10:10

svoop