Forum Discussion

aa1's avatar
aa1
Contributor
5 years ago

Regex

Hi,

 

I was trying to implement something similar to the following https://support.smartbear.com/testcomplete/docs/scripting/regular-expressions.html

 

var regEx3 = /;(\r\n)+function/g;

var ReplacementLines = ";\r\n\r\n//A helper routine\r\nfunction";

var test1 = "function Foo(Param1)";

var test2 = test1.replace(regEx3,ReplacementLines);

 

but it does not give me the result as expected.

 

var test = "class=organizationAgentGridInfoRightColumn_Text12345";

var regEx = /<=organizationAgentGridInfoRightColumn_Text>.*/gi;

test = aqString.Replace(test,regEx,"abc");

 

Not sure what I am doing wrong. Is my regex wrong?

  • Wamboo's avatar
    Wamboo
    Community Hero

    Hi aa1


    Can You write more about this one? I think i can help You but i need more information.


    For what for You need this? excel file? script routine?


    what exactly do You want to replace and what is the complete form of the string?

    • aa1's avatar
      aa1
      Contributor

      Hi Wamboo,

       

      Thank you for the reply. I need it for automation script. I am using test complete to compare two html files - actual vs. expected. But there are some of the lines that I would like to ignore. So I want to use regex to find those lines and replace with a whitespace or some characteres so that the testcomplete passes the test. Right now I drilled down to very simple expression:

       

      Example: If i try regex tester such as http://regexstorm.net/tester, , it shows 1 match but test complete says 0 match for the following so I am assuming regex dont work the same way as it normally does in test complete.

       

      var test1 = "agent_1a2b3c_LangPref_0";
      var regEx = "(?<=agent_).*?(?=_)";
      var ppp = aqString.StrMatches(regEx,test1);
      
      
      

      Test complete gives ppp = false which means it did not find any match. I dont seem to understand why. You have any ideas?

       

      Regards,

      aa

      • aa1's avatar
        aa1
        Contributor

        Hi again,

         

        Furthermore, looks like testcomplete has its own non native regex methods. So I was trying those but that did not take me anywhere either.

         

        For example:

        var testString = "agent_1d74901d5";
        var testRegex = /\agent\_\a/;
        var re = new RegExp(testRegex);
        var rr = re.test(testString);
        
        

        I dont understand why rr is false. Is that not how you would specify the regex?

         

        thanks

        aa