Regex expression validation is not working
Options
- 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
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 11:24 AM
@snow57 Use Escape character (\) to match with a reserved letter of regex.
For example if you wish to match $ then it would be written as \$ if you wish to match / then it should be written as \/ if you wish to match \ then it should be written as // in the regular expression.
var nonPrint = "123Test*input";
gs.print('nonPrint1 '+nonPrint);
var regex =/^[0-9][0-9]*\$/;
var s = nonPrint.replace(regex, '_');
gs.print('nonPrint2 ' + s);
Hope this helps.