Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (12.7k 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 = \w+@\w+.\w;

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

WScript.StdOut.WriteLine(result);

1 Answer

0 votes
by (29.5k 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(/\w+@\w+\.com/);

            //returns the email address
     }

  WScript.StdOut.WriteLine(result);
}

 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...