Replace only first string from website

0 Answers 263 Views
Fiddler Classic FiddlerCore
eric
Top achievements
Rank 1
eric asked on 16 Jul 2021, 07:19 PM

Hello everybody

i have this code in fiddlerScript :

        if(oSession.HostnameIs("example.com")) { 
            oSession.utilDecodeResponse();
            oSession.utilReplaceRegexInResponse('text-align: left; width: 120px;">[^<]*</span>','text-align: left; width: 120px;">xxxxxxxxx</span>');
            oSession.utilReplaceRegexInResponse('text-align: left; width: 145px;">[^<]*</span>','text-align: left; width: 145px;">yyyyyyyy</span>');

---------------------------------------

In the webpage there is more element that will begin like that :    text-align: left; width: 145px;

my question is : how can i replace only the first string that will seen on the webpage , not all  ?!?!

thanks !

Lini
Telerik team
commented on 20 Jul 2021, 09:53 AM

The utilReplaceRegexInResponse() method does not allow customizing the number of replacements. You can use another method - utilReplaceOnceInResponse() to replace only once, but it does a simple string replace, not using regular expressions. 

If you want to use regular expressions, then you have to use a feature called negative lookbehind (?<!...) that allows you to replace only the first match. Here is an example of how to use it in your case: Regex example

The search string should become

(?<!text-align: left; width: 120px;">[^<]*</span>.*)text-align: left; width: 120px;">[^<]*</span>

No answers yet. Maybe you can help?

Tags
Fiddler Classic FiddlerCore
Asked by
eric
Top achievements
Rank 1
Share this question
or