Javascript + Replace forward slashes ‘/’ with backward slashes ‘\’.

Hi friends,

Using following Javascript sysntax you can replace forward slashes (‘/’) with backward slashes (‘\’) :

var strReplace = “C:\Temp\Temp1\Temp2\text.jpeg“;

strReplace = strReplace.replace(new RegExp(/\\/g),”/”);



About Vijay Modi

Having 12+ years of experience in web application development. Expertise in various domains like E-Commerce, E-Learning, Insurance. I have expertise in web application development, window application development, Performance improvement, bug fixing etc. I have worked on various Microsoft technologies including ASP.Net, MVC, WebApi, WCF, Entity Framework, WPF, Window Application Development, AWS, Azure, AngularJS 2.0 / 1.5.2, .NetCore framework, jQuery. I am believing in quality work and achieving deadlines. Also like to work on new technologies and quick learner.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

12 Responses to Javascript + Replace forward slashes ‘/’ with backward slashes ‘\’.

  1. blueprints says:

    Javascript String Replace Path

  2. Megharaja says:

    Thanks a lot for the valuable solutions.

  3. Hussain says:

    Nice Code, Thanks a lot

  4. Mario says:

    Hi, how would it be shifted, I mean, Replace backward slashes ‘\’ with forward slashes ‘/’.

  5. Trueman says:

    That is right, your description is wrong, you are replacing \ for /….
    what about the opposite one, how could it be done?

  6. Lou says:

    Use this to replace “/” with “\”. The code may not look right depending on your code editor, but it’ll work.

  7. Lou says:

    oops, forgot to add the code:
    strReplace = strReplace.replace(/\//g, “\\”);

  8. Lou says:

    Here is the code you guys are asking for:
    strReplace = strReplace.replace(/\//g, “\\”);

  9. Jens Haase says:

    Hi Lou,

    this doesn´t work with the built-in Javasript of Adobe Acrobat (V. 9.3). Do you have a solution for the Adobe crippled Javascript?

  10. Pingback: Punkchip | Removing forward slashes from a string

  11. manthan says:

    got error invalid expression

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.