Forum Discussion

tvklovesu's avatar
tvklovesu
Frequent Contributor
2 years ago

Find part of a string with regular expression in a given string

Hello,

I have a test where I need to create filters with text using logical operators as below. In the results it returns all the matching records. I am not getting any idea how to test this with TestComplete aqString method.

For ex. when I search with text "Surface Active", here I need to use quotes in the search term. The results returned as DORGANIC SURFACE ACTIVE PRODUCTS AND PREPARA

Now I need to verify if the given text Surface Active exists in the results returned. 

The issue is my variable to enter the search text will be like "surface Active". When I use aqString.find method that will return false because the quotes doesn't match.

 

         

 

I have few other logical operators similarly to use and like to know the best approach that I can do to verify.

 

7 Replies

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Thanks for your input. Actually I wrote my own function to test those three operators as below. Please let me know if you think I can still simplify this. Also I need to test one more condition that is when searched with text along with ~ (Ex. Muhamed~ returns results including Muhammad, Mohamed, Muhammed, etc.). Is there any way that I can test if the string is similar to what I searched for. I tried looking in to the reqular expressions but can't find it.

       

      function VerifyString(colString, operatorType){
      wordCount = stringArry.length-1
      result = []
      if (operatorType=='and'){
        for (j=0;j<=wordCount; j++){
          if (aqString.StrMatches(stringArry[j], colString) ==true){
            result.push(true)
          }else{
            result.push(false)
          }
          if (result.indexOf(false)==0){
            Log.Error("The text in the column "+colString+" doesn't contain the word "+stringArry[j])
          }
        }
      }
      if (operatorType=='or'){
        for (j=0;j<=wordCount; j++){
         if (aqString.StrMatches(stringArry[j], colString) ==true){
           result.push(true)
         }else{
           result.push(false)
         }
        }
        if (result.indexOf(true)==-1){
          Log.Error("The text in the column doesn't contains any of the search words "+colString)
        }
      }
      if (operatorType=='not'){
        for (j=0;j<=wordCount; j++){
         if (aqString.StrMatches(stringArry[j], colString) ==true){
           result.push(true)
         }else{
           result.push(false)
         }
         
        }
        //Log.Message(result.indexOf(true) +", "+result[wordCount])
        
        if (result.indexOf(true)==-1 || result[wordCount] != false){
          Log.Error("The text in the column doesn't match with the search string "+colString)
        }
      }
      }

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The solution is to write your own algorithm. What you are requesting is not a standard "search" function, so there won't be many results if you do an internet search.

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      I looked at that method and was able to utilize few of them like (", ?, *) and was able to achive what I want to do. but for the other logical operators like And, Or, Not etc I can't find any solution. Do you have any other thoughts that I can try.

      Thanks

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      Sorry for the late reply. I looked and can't find what I am looking for. If you come across and have a solution, please post that here.