Unable to replace backward slash "\" from a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2018 04:12 PM
Hi All,
I am trying to split/replace a string that has backward slash"\" but unable to get the desired result.
var strVal = "Au\Group\This group"
var newStr = strVal.replace(/\\/g,"/"); [ or var newStr = strVal.split("\'");]
gs.info(newStr)
**Script completed in scope : AuGroupThis group
Is there any other way to achieve this. Any advise/inputs will be of great help.
Thank you.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 03:13 AM
Hi Arpitha,
I have similar use case, Did you get any solution for this.
Thanks,
Sowmya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 06:29 AM
There's no solution because in JavaScript, a backslash "\" is an escape character.
As such, following code will treat "\G" and "\T" each as a single character and would output 17. This is JavaScript language specification.
var strVal = "Au\Group\This group";
gs.info(strVal.length);
The problem is on setting the string variable to contain a single backslash. A single backslash should be replaced with double backslash before the value is set to a JavaScript variable.