String.split(" ") not working

jasonthorngren
Giga Contributor

Trying:

 

var regexp = /Status:(.*)/g;
if (str.match(regexp)) {
str = str.match(regexp);
gs.log('*** ISSUE: strRegEx = ' + str); 
var status = str.split(" ");
gs.log('*** ISSUE: Status = ' + status[1]);

Getting: 


Information	*** ISSUE: strRegEx = Status: Done (was: Testing)

Warning          org.mozilla.javascript.EcmaError: Cannot read property "1" from undefined
Caused by error in sysevent_script_action.95636cdbdba1181072bea04913961902.script at line 10

7: str = str.match(regexp);
8: gs.log('*** ISSUE: strRegEx = ' + str);
9: var status = str.split(" ");
==> 10: gs.log('*** ISSUE: Status = ' + status[1]);

Information	*** ISSUE: Status = undefined
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It looks like it's not able to split str, so forcing str to a string should do it

str = str.match(regexp).toString();

View solution in original post

6 REPLIES 6

hammad ul aziz2
Mega Guru

Here is the solution.

var str='Status: wlerkjwlkr';
var regexp = /Status:(.*)/g;
if (str.match(regexp)) {
str = str.match(regexp);
gs.print('*** ISSUE: strRegEx = ' + str); 
var status = str.toString().split(" ");
gs.print('*** ISSUE: Status = ' + status[1]);
}

Ct111
Giga Sage

var regexp = /Status:(.*)/g;

add this line              var k = str.match(regexp);

if (k.length != 0)                                          // to check whether match is found or not.

{

str = str.match(regexp);

gs.log('*** ISSUE: strRegEx = ' + str);

var status = str.split(",");                           // change your line to this.

gs.log('*** ISSUE: Status = ' + status[1]);

}

 

Try this and let me know if this helps

 

Mark my ANSWER as CORRECT and HELPFUL if it helps