Home » Java Script » Java script remove backslashes and forwardslashes from a string

Java script remove backslashes and forwardslashes from a string

How can I remove backslashes and forwardslashes from a string or remove forwardslash from a url using java script.I’m going to explain to do this by using regular expressions and simple core java script.

1-Remove Backslashes

Backslash (\)

2-Remove Forwardslashes

Forwardslash (/)

Note here is the regular expression /\//g and /\/$/. The piece of the string you want replacing is written between the first and last forward slashes.
If you wanted the word ‘book’ replaced you would write /book/g.

Tags

Similar posts