Forum Discussion

alejandro_canos's avatar
alejandro_canos
Occasional Contributor
10 years ago

regular Expressions in TestComplete

Good afternoon am Alejandro Canosa I have a number of concerns with regular expressions in TestComplete, I use the following method to evaluate aqString.StrMatches regular expressions (regexp, Zip) and regexp I assign the expression [0-9] {3,5} to allow numbers with 3-5 digits but when the Zip field is given a number that satisfies the condition I return false as if the value did not meet the condition, the problem is the method I use or regular expressions in TestComplete vary with the standard web? I would appreciate someone much more knowledgeable than I to explain to me or enlighten me because it's something I do not quite ented, thank you very much in advance
  • Hi,

    Could you please post a sample of the code that is failing and an example of the data that is failing.  It would be most helpful at investigating the issue.
  • Hey Alejandro,



    I seem to come to the same conclusion (aqString.StrMatches returning false) as you. Bizzare, seems more complex expressions confuses the function :).



    You can perhaps use a workaround for this (see below)?



    Something like:



    //JavaScript


    var str = "15121";


     


    var isNumber;


    //This will search for digits [0-9] from the begining of the string (^) till the end ($)


    //that has length 3,4,5 {3,5}


    var pattern = "^[0-9]{3,5}$";

    var regexpattern = new RegExp(pattern); 

    //exec returns null for no match, otherwise the string

    var res = regexpattern.exec(str);


    //inspect

    isNumber = (res != null ? true : false);



    //return

    return isNumber




    Regards,

    Altus
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi all,



    The aqString.StrMatches method doesn't support the repeat count in {}. It uses {} to designate match groups. You can read more about aqString's regex syntax here.



    If you need regular expressions with repeat count, use JScript's native regex engine as in Altus's example.
  • Hi,

    Could you please post a sample of the code that is failing and an example of the data that is failing.  It would be most helpful at investigating the issue.
  • alejandro_canos's avatar
    alejandro_canos
    Occasional Contributor
    of course , attached 2 files , one with the code and another with information that brings the database , thank you very much for answering
  • alejandro_canos's avatar
    alejandro_canos
    Occasional Contributor

    Hello everyone:


     


    thanks for replying, I'll try now but have Logita, this expression is common to many languages


     


    regards