How to replace values using regex

lakshmir
Giga Contributor

Hi All,

Can somebody help me how to replace values using regex

5 REPLIES 5

rezacol
Mega Expert

Tell me your requirement. I mean what you want to replace. For example, do you want your string to replace letters from alphanumeric values or else ??


lakshmir
Giga Contributor

Hi


I need to replace string with alphanumeric numbers.


Thank you in advance.


Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you already know the regex you want to use, you can just use the replace() method. For example, if you want to replace all spaces with dashes in a string you could use:



var str = "Replace the spaces";


gs.log(str.replace(/\s+/g, '-'));



Prints:


Replace-the-spaces


Thank you:)