Regex expression validation is not working

snow57
Tera Contributor

Hi, 

 

The regex validation in the below code is not working. could someone please help me on this .

 

 

var nonPrint = "123Test*input";
gs.print('nonPrint1'+nonPrint);
var regex =/^[0-9][0-9]*$/;
var s = nonPrint.replace(regex, '_');
gs.print('nonPrint2' + s);

 

Appreciate for the leads.

 

Thanks

5 REPLIES 5

Sandeep Rajput
Tera Patron
Tera Patron

@snow57 Try the following.

 

var nonPrint = "123Test*input";
gs.print('nonPrint1 '+nonPrint);
var regex =/^[0-9][0-9]*/;
var s = nonPrint.replace(regex, '_');
gs.print('nonPrint2 ' + s);

 

Here is the output.

*** Script: nonPrint1 123Test*input
*** Script: nonPrint2 _Test*input

Hope this helps.

Hi Sandeep,

 

Thanks for assisting. it has to replace the "*" too right ?

 

 

I removed the $ in regular expression as it forcefully asserts the position at the end. Hence the string was failing. Please mark the answer correct and helpful if it manages to address your requirement.

Hi, 

 

In the Regex , i have to include those too like $ ,/, \ etc.., Any clue that needs to take in to count .

 

Thanks