Regex expression validation is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:31 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:42 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:45 AM
Hi Sandeep,
Thanks for assisting. it has to replace the "*" too right ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:47 AM - edited 10-17-2023 10:47 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:55 AM
Hi,
In the Regex , i have to include those too like $ ,/, \ etc.., Any clue that needs to take in to count .
Thanks