Forum Discussion

Poida's avatar
Poida
Occasional Contributor
6 years ago
Solved

Find and Replace with Regular Expression in Script using Javascript

Hi, i'm having trouble with doing a find and replace using regex on a string in a script using Javascript.   The idea is to get rid of all multiple consecutive white space characters in the strin...
  • Poida's avatar
    Poida
    6 years ago

    Thanks tristaanogre,  that tipped me off.  Needed the gi switch at the end to work and it was using the javascript re syntax not the native testcomplete one.  Below is the working code. 

     

    function UseRegex()
      {
        var regex = /\s+/gi;
        var Instr = "    Words    with too much space    |";
        var ResStr = Instr.replace(regex," ");   
        Log.Message(ResStr); 
      }