0 votes
1 view
in RPA by (11.8k points)

I have an "Invalid character error" while using JS script to extract emails from the text that I cannot handle for the last 2 days.

enter image description here

I am getting a text from web application by using Object cloning and passing it to a variable which I will later pass to JS script.

enter image description here enter image description here

And of course, my JS script which I checked and it works:

var args = WScript.Arguments;

var pattern = \[email protected]\w+.\w;

var result = /pattern/.exec(args);

WScript.StdOut.WriteLine(result);

1 Answer

0 votes
by (27.7k points)

The issue here is that you are passing a string to JS and using var input = WScript.Arguments, this will not return you the string but just a single word, you can change your JS in the following way and it should work.

var args = WScript.Arguments;

if (args.length > 0)

    var val=0;
     var str=args.item(0);
    var ary = str.split(",");
    //WScript.Echo(ary.length);

    // for loop in case there are multiple parameters passed
     for (var i=0; i < ary.length; i++)
     {


            //Takes the input passed as parameter
            var input = (ary[i]);

            // Uses the Match() Method to look for an email address in input string
            var result = input.match(/\[email protected]\w+\.com/);

            //returns the email address
     }

  WScript.StdOut.WriteLine(result);
}

 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...