1 d
Javascript forward slash in string?
Follow
11
Javascript forward slash in string?
Such expressions are not a panacea for everything. We can observe f we put the whole URL in encodeURIComponent that the forward slashes (/) are also converted to special characters. Need a JavaScript developer in Australia? Read reviews & compare projects by leading JavaScript development agencies. The backslash \ character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. There are three single quote ' marks, and the parser doesn't know what is part of the string and what. You escape it by putting a backward slash in front of it: \/ For some languages (like PHP) you can use other characters as the delimiter and therefore you don't need to escape it. Here's the output from Node:. Globally replace a forward slash in a JavaScript string. Method 2: Splitting in place of the forward-slash and joining it back with the required string. That said, the best answer is probably to use a split and a. Much of the modern web would be vastly different if not for JavaScript, th. They might not be so enthusiastic about. Consider this below string in JavaScript: "TEST NAME\TEST ADDRESS" (it contains only one "\" which cannot be changed). Discover Java string comparisons with the equals() method and double equal operator and learn how to use them in your software. Get value of a string after last slash in JavaScript javascript get characters between slashes. Walmart is cutting prices on some iPhones and Samsung smartphones for three months, including the new iPhone SE. At the same time I have to make sure that "Test/World" will come as it is in path. A regular expression ( regex for short) allow developers to match strings against a pattern, extract submatch information, or simply test if the string conforms to that pattern. In URLs, special characters like the slash (/) can interfere with the normal parsing of the URL, so they need to be percent-encoded (also known as URL encoded). stringify-ied an already valid JSON string (which adds the forward slashes) and now you are trying to parse it - that's what is really going on here Commented Nov 23, 2017 at 23:31 parse javascript string Parse JSON having back slashes - Javascript Parsing a JSON string in. var str = 'some // slashes', replacement = ''; var replaced = str. I tried replacing with file separator which gives "\" and then splitting with "\\" works but not the below code. The replace() function takes two arguments: the substring we want to replace, and the replacement substring. querySelector("button"); let output = document. Basically you just need to escape the escape character in your replacement stringreplace(new RegExp('/','g'),"\\/"); edited Sep 4, 2015 at 0:23. , is common practice. Jul 22, 2015 · 10. I want to split words by single slashes only: text1/text2- split. But, most likely a faster and simpler solution is to use your language's built-in string list processing functionality - i ListLast( Text , '/' ) or equivalent function. strip() function on the string. The problem in the question is that the string literal "This is my \string" contains zero backslashes. I suspect your problem is elsewhere. The anchors ^ and $ are important otherwise it will verify a string as OK with other stuff before or after. Note: Prior to PHP 5. GitHub, the popular developer platform owned by Microsoft, has laid off virtually its entire engineering team in India. The reason is simple: among a few other chars, it'll encode the forward slash and amersand that encodeURI will not What's the use? Say you want to encode a URL and pass it in the query string, this will let you encode all the characters so you get something like. I had to convert an URL to a string in another format, so initially, I tried str. log (newStr); // "hello/". Then I thought oh I might need to use a. replace(/\\/g, "\\\\"), or str Mar 17, 2017 · Path with backslashes to path with forward slashes javascript. May 17, 2012 · JavaScript and forward slashes in strings. Slash in string disappears in HTML file href linked to javascript function not working Slash escape in. Converting backslashes into forward slashes using javascript does not work properly? 0. Try this: myString = '/courses/test/user'; myString = myString. Example const str = '/questions/ask/1' const strReplace =. Regex - strip out text between first and second forward slashes JavaScript: Replace last occurrence of forward slash. We should double for a backslash escape a forward slash / in a regular expression. how to replace the forward slash to backslash and forward slash using javascript Javascript 2022-03-27 22:25:20 javascript download string as file Javascript 2022-03-27 21:40:22 sort numbers in array javascript Javascript 2022-03-27 21:20:04 compare two arrays and return the difference javascript How can i remove sub string (after last slash) from string in javascript like c:/Program File/Internet Explorer to c:/Program File/ There are numerous ways to detect whether a string contains a forward slash or not. A regular expression ( regex for short) allow developers to match strings against a pattern, extract submatch information, or simply test if the string conforms to that pattern. I'm trying to perform the following action on a string : find the last occurrence of the character "/"; remove everything before that character; return the remains of the string; To be more explicit, let's say I have the following string : var string = "/Roland/index. We have a few methods to do this which are described below: Using replace() method with a regular expression; Splitting in place of the forward-slash and joining it back with the required string; Method 1: Using replace() method with a regular expression. Backslash \ is used as an escape character for strings in JavaScript, and in JSON. How you access it depends on your language, but you'll basically just want a capture group for whatever falls between your second and third "/". replace() method returns a new string with the matches of the pattern replaced. Replace Backward Slashes with Forward Slashes Javascript javascript regular expression - remove extra slashes from output Javascript trim double slashes Remove slashes from Start and end of the URL Since the goal is changing the url with a one-liner, the following solution can also be used: url = url. \/([a-zA-Z0-9]{0,}) I hope this helps Get value of a string after last slash in JavaScript. What you are seeing is likely syntax highlighting from your code editor/IDE. I am trying to remove a forward slash from a date string. Replace Backward Slashes with Forward Slashes Javascript javascript regular expression - remove extra slashes from output Javascript trim double slashes Remove slashes from Start and end of the URL Since the goal is changing the url with a one-liner, the following solution can also be used: url = url. The following examples are equivalent to match a string containing the value /tmp: This is my string: hello/page/2/bye This is what I would have (please note that "2" could be any number, "page" is always "page": hello/bye How can I do with str. Ask Question Asked 8 years, 6 months ago javascript; jquery; json; slash; or ask your own question. String quotes "consume" backslashes and interpret them on their own, for instance: \n - becomes a newline character, \u1234 - becomes the Unicode character. Discover Java string comparisons with the equals() method and double equal operator and learn how to use them in your software. stringify-ied an already valid JSON string (which adds the forward slashes) and now you are trying to parse it - that's what is really going on here. replace(/\//g, '\\/'); but it would get the string with the \/. I have a small suggestion based on antyrat's answertoString(). Note that the regex just looks for one backslash; there are two in the literal because you have to escape backslashes in regular expression literals with a backslash (just like in a string literal). However, also using the native constructor of RegExp, that accepts a string as first argument, you also need to escape slashes, and twice. replace() using jQuery? In addition, it encodes the following characters: , / ? : @ & = + $ #. The easiest way to get rid of a forward slash in a string using JavaScript is with the JavaScript String replace() function. The debugger displays all strings in a way that they could be pasted into C/C# code. Here's how to disable it. I was trying to concatenate two string variables and have them separated by a backslash, so i used the following: newString = string1 + "\ ". replace(/\//g, replacement); answered Dec 30, 2010 at 22:34 0. String quotes "consume" backslashes and interpret them on their own, for instance: \n - becomes a newline character, \u1234 - becomes the Unicode character. One could maybe overload the function or extend the class but I found the easiest way is to add a unique string such as guid and then replace that guid with your Uri string after the calling the toString () function. The String. replace won't handle repeated occurences. Forward slash is a special character, we need to escape it using (). The replace() function takes two arguments: the substring we want to replace, and the replacement substring. iv certification bergen county nj Need a JavaScript developer in Chicago? Read reviews & compare projects by leading JavaScript development agencies. var firstString = url. What is an acceptable way to remove a particular trailing character from a string? For example if I had a string: > "item," And I wanted to remove trailing ','s only if they were ','s? Thanks! I'm working with a Google API that returns IDs in the below format, which I've saved as a string. ]; Only a escaped backslash will make a backslash in a string '\\'. Jan 14, 2019 · 1. I want to remove parentheses and forward slash or backslash ()/\ from the string. So, it sounds like the optionalSlash should be in the string before label or count, and if label or count is missing, we skip adding the optionalSlash for that variable. The predefined characters are: single quote (') double quote (") backslash (\) NULL. Forward slash is a special character, we need to escape it using (). I had to convert an URL to a string in another format, so initially, I tried str. I'm writing a cross platform file explorer in python. ]; Only a escaped backslash will make a backslash in a string '\\'. Jan 14, 2019 · 1. Several browsers (namely, Firefox & Opera) fail catastrophically when encountering URIs with backslashes. Forward slash in a JavaScript variable Javascript not writing forward slash jquery forward slash escape Slash in string disappears in HTML file href linked to javascript function not working Slash escape in javascript How to remove forward and backward slashes from string in javascript Hot Network Questions Clarification needed about my Schengen visa (CZ, DE, SK) I use query_string because I want to give my users the possibility to do complex queries with OR and AND. Andrew Cooper's answer is correct in terms of why that third statement is going wrong. When General Electric fired its CEO a month ago, investors cheered the move. parse(jsonString); String. In the case of a single back slash in the string, the javascript replace method did not allow me to replace the single back slash. So, it sounds like the optionalSlash should be in the string before label or count, and if label or count is missing, we skip adding the optionalSlash for that variable. happy steak (It's supposedly so that \$ will be a literal dollar sign, but I. replace () to remove a trailing slash without the need to first explicitly check if a trailing slash exists and then remove it (as in the other methods). Find a company today! Development Most Popular Emerging Tech D. Your string does not contain any backslashes, but esaped \j, and \t wich is the value for tab. Triple slash doesn't mean anything special, but it might be a comment that was added right before a division. Thought it would be the following but it doesn't work: path. Regex patterns in Java is given as String values; Metacharacters (such as ? and. replace(/"/g, '\\"'); This extra step will replace all the \" to " first, and then replace all the " back to \". I'm trying to replace backslashes with forward slashes in javascript with the replace function and regex but can't get it to work. Replace Backward Slashes with Forward Slashes Javascript javascript regular expression - remove extra slashes from output Javascript trim double slashes Remove slashes from Start and end of the URL Since the goal is changing the url with a one-liner, the following solution can also be used: url = url. replace (/\/?$/, '/'); If the trailing slash exists, it is replaced with /. You see, "\\/" (as I'm sure you know) means the replacement string is \/, and (as you probably don't know) the replacement string \/ actually just inserts /, because Java is weird, and gives \ a special meaning in the replacement string. New to Microsoft Teams? Check out the different slash commands to make your team collaborations much easier. The forward slash (/) is a special character in regex, necessitating escape. Consider expanding your answer to explain to the asker why this. Learn how to encode and decode forward slash ('\\u002f') in Java strings and why it is different from other escape characters. I need to do this for configuration purposes. It allows you to search for a specific part of a string, called a substring, and then replace it with another substring. We are going to use the simplest approach which involves the usage of the regex pattern as well as replace() method. Some of Microsoft's ASP. I have used encodeURIComponent and str. Split string on backslash or forward slash splitting of strings in javascript which involves backslash Split on backslash merges split elements Get string value after a backslash (\) in JavaScript. 1. \ is correct in a Windows file path and / is correct in a URI. ronnie soft white underbelly The query string is: "my params / separated by slash". Jun 26, 2020 · Today I learned an easy solution to replace all occurrences of a forward slash in string in javascript. The forward slashes / / mark the beginning and end of the regular expression. replace(replacedtext, newtext) and RegEx. When General Electric fired its CEO a month ago, investors cheered the move. If the trailing slash does not exist, a / is appended to the end (to be exact: The trailing anchor is replaced with / ). The Workers' Edge blog at CNET posts a handful of shortcuts and tweaks for Firefox and Internet Explorer, some of which we've covered here before, but the author points out a Firef. You got to tell C to not use your backslash as an escape sequence by adding an extra backslash to your string. Concatenating them won't magically turn them into a single Unicode escape. This is a forward slash: / Commented Sep 22, 2020 at 3:33 ah sorry for misguiding - alper. Javascript get text between last 2 forward slashes Javascript : Get value of first and second slash. I have a string that takes the form of a path, for example: Year 1 / English / Writing / How to write your name I need to produce a string which is everything after the second forward slash I need support with splitting text string in VBA Excel. New to Microsoft Teams? Check out the different slash commands to make your team collaborations much easier. Nick Schäferhoff Editor in Chief Below you can find the Javascript cheat sheet in. Learn about time travel physics and how time travel physics work. Advertisement We've. This is my code: var str = 'some\stack\overflow', replacement = '/'; var replaced = str. Advertisement Have you ever tried to make string? It's actually a bit tricky. A file path and a URI are different. They might not be so enthusiastic about. GitHub, the popular developer platform, has laid off virtual. replace (/\/?$/, '/'); If the trailing slash exists, it is replaced with /.
Post Opinion
Like
What Girls & Guys Said
Opinion
14Opinion
txt"; If you want the absolute path of a file then you can. Jul 18, 2012 · I'm making a small web app in which a user enters a server URL from which it pulls a load of data with an AJAX request. replace() method likereplace('/', ":"); But to my surprise, it only replaced the first occurrence in the string. ” – David Seller “The catch about not looking a gift horse in the mouth is that it may be a. The new string returned by this method will be stored in the result variable. replace (CharSequence, CharSequence) example provided by @PaulPRO and @Bohemian will work, but its better to use the String. In JavaScript, regular expressions are also objects. We used two backslashes next to one another. This string is ambiguous: 'He's going to the park'. What is the real reason that we must escape a forward slash in a JavaScript string, and also why must we escape string/no string in XHTML. The forward slashes / / mark the beginning and end of the regular expression. I need your help, How do I go about replacing all instances of a dash - with a forward slash / in a string var x = "03-04-2014" After conversion: var x = "03/04/2014" The query string contains a slash (/), which cause to the url to be cut by the site, because it doesn't see it as part of the query string. stringify(objMap) What's happening is you are double json encoding your values array - note that your "invalid" JSON value is actually a JSON string rather than the array that you want. The plus + matches the preceding item (the forward slash) 1 or more times. Learn what Javascript is and how to build a simple calculator with it. Backslash \ is used as an escape character for strings in JavaScript, and in JSON. So whether its "action" or "adventure", etc. We are going to use the simplest approach which involves the usage of the regex pattern as well as replace() method. The forward slash (/) is a special character in regex, necessitating escape. The request: Json with slash in string. – Adam Jenkins Apr 5, 2022 · So, it sounds like the optionalSlash should be in the string before label or count, and if label or count is missing, we skip adding the optionalSlash for that variable. Backslash \ is used as an escape character for strings in JavaScript, and in JSON. wqow weather radar Jan 3, 2017 at 18:46seashell : I know this is the expected, but I am searching the way to remove slash Learn how to replace commas with slashes in JavaScript on Stack Overflow, with solutions and code examples. You can use the digit-class of Regex for that, it is \d. replace(/\\/g, "\\\\"), or str Mar 17, 2017 · Path with backslashes to path with forward slashes javascript. This last part of the url (after the last forward slash "/") will be different each time. Oct 18, 2015 · you create a string in javascript by putting the string inside quotations: var answer = "It's alright"; var answer = "He is called 'Johnny'"; var answer = 'He is called "Johnny"'; Which you have correctly done. replace(/\//g, replacement); answered Dec 30, 2010 at 22:34 The first matches the start of the string, the second the end test ( "blah" )); show ( /^a+$/. Note: I need to allow forward slash to particular class instead of doing all input fields. And the forward slash is not a special character, so you do not need to escape that. php"; // Which is a result of windowpathname On how regex complicates things. You could easily replace the forward slashes / with something like an underscore _ such as Wikipedia uses for spaces. You don't need regex for such a simple task. Javascript get text between last 2 forward slashes Javascript : Get value of first and second slash. strip() + string2 "but the existing Microsoft library (SystemScriptJavaScriptSerializer) expects forward slashes to be escaped" Not in my experience. No need using any character references or entities. Replacing '/' with %2F or %252F in uuid. How can I write a Regular Expression in javascript to trim the string to only the characters after the last slash in the URL. If for example the dd300 is always follwed by two slash separated numbers it can be The regular expressions matches the first example with the full stops in the date, but does not match the second and third example with the dashes and forward slashes in the date. replace("\", "/"); console. I had to enable ALLOW_ENCODED_SLASHES for Apache). var firstString = url. Split Javascript string containing single backslash to two strings. The function should return a new string with all the backward slashes replaced with forward slashes. squibble This is usually because the server side code didn't properly create the JSON. These patterns are used with the exec and test methods of RegExp, and with the match, replace , search, and split methods of String. So this regular expression is invalid: /{//. How can I write a Regular Expression in javascript to trim the string to only the characters after the last slash in the URL. It seems that the source of the problem is a string value check within the JSONObject "put" function that adds the extra slashs. By clicking "TRY IT", I agree to receive newsletters and promotions. - CertainPerformance. I want to remove parentheses and forward slash or backslash ()/\ from the string. Here is a working js example: JS code Dec 17, 2015 · In order to correct the forward and back slash accordingly to your system you can use path module of Node Like here is a messed path and I want it to be correct if I want to use it on my server. Cosmic String - Time travel physics are closely based around Einstein's theory of relativity. How you access it depends on your language, but you'll basically just want a capture group for whatever falls between your second and third "/". In an HTML 4 document, the sequence inside an element defined as containing. It is required for some characters to remove ambiguity from string literals. You cannot preserve the "exact" string when you stringify, since parsing a json. Need a JavaScript developer in Chicago? Read reviews & compare projects by leading JavaScript development agencies. We used two backslashes next to one another. JavaScript error: SyntaxError: unterminated string literal I can not change HTML along with product code; the option for me is to change it in JS. Forward slash is a special character, we need to escape it using (). I want to replace all backward slashes in it with forward ones so it looks like: Snippets in JavaScript: Double slashes in URLs. If that's true, you could do a simple ternary when constructing the string. For example, alert("\\\\") will show a. what is an ancient dragon worth in adopt me You don't need regex for such a simple task. querySelector("h1"); Try =REGEXREPLACE(B4, "/[^/]*$", "/") or with "/[^/]*/?$". I tried to google it, not quite sure what to call it. It is a way to divide up long addresses, helping to create a more user-friendly URL. Learn about time travel physics and how time travel physics work. Advertisement We've. I recognize I can change to put resource as a parameter, but I would rather not as I use this approach successfully where the arguments are integers. They aren't really in the transmitted data. Office Technology | Listicle REVIEWED BY: Corey McCraw Corey McCraw is. Several browsers (namely, Firefox & Opera) fail catastrophically when encountering URIs with backslashes. Let's say the following is our string − const str = 'Th/s str/ng /conta/ns some/ forward slas/hes'; Use a regex literal with the g modifier, and escape the forward slash with a backslash so it doesn't clash with the delimiters. You probably want "/\\d+/" in Java. Which I believe it's not the case in this code snippet This is the answer according to the title as the title is " Remove all slashes in Javascript " not backslashes. \/([a-zA-Z0-9]{0,}) I hope this helps Get value of a string after last slash in JavaScript. First character is at index 0The position (up to, but not including) where to end the extraction. Do you want to know how to insert slashes automatically in date fields? Learn from the experts on Stack Overflow, the largest and most trusted online community for developers. To add a slash to a string in JavaScript, you can use the + operator. replace (CharSequence, CharSequence) example provided by @PaulPRO and @Bohemian will work, but its better to use the String. For your URL example, if you wanted to add text before the first slash with word characters on either side, you could do. It is easy to add a forward slash, just escape it. No need using any character references or entities. replace(/[/\\*]/g, ""); The only character you need to escape in vbscript is the double quote, which escapes itself: MyString = "He said, ""Here's how you escape a double quote in vbscript. Watch this video to find out about the EGO Power+ cordless string trimmer powered by a 56-volt, lithium-ion battery for increased performance and run time. Actually, your last example is unclear, since there is a / in the string May 11, 2018 at 12:58. The api call fails saying the meeting doesn't exist because it is unable to recognize the forward slash '/'.
We have a few methods to do this which are described below: Methods to globally replace forward slash: Using replace() method with a regular expression Using JavaScript split() method Using JavaScript replaceAll() method Method 1: Using […] We are displaying the original string in the h1 element using the innerText property. Find a company today! Development Most Popular Emerging Tech D. @Code_S: You also have to escape the backslash in the string var path = "C:\\test1\\test2";. Regular Expression To Match Forward Slash. We should double for a backslash escape a forward slash / in a regular expression. We are displaying the result in the h1 element using the innerText property. 'res/js/test', 'res\\js\\test', 'res/js\\test', 'res\\js/test'. toyota hilux hardtop canopy As we may recall, regular strings have their own special characters, such as \n, and a backslash is used for escaping\d" is perceived: alert("\d\d. I have string of the following format. Concatenating them won't magically turn them into a single Unicode escape. Jan 1, 2021 · Share this: Forward slash can be replaced in Javascript by using replace () method or split () & join () methods. Get value of a string after last slash in JavaScript javascript get characters between slashes Javascript: Find index of slash (/) in a string. You can use a regular expression with
str. But we’re stuck in some problems that I’ll try to explain in this article and provide a solution. BTW: These slashes are backward slashes. toca boca pfp The forward slashes / / mark the beginning and end of the regular expression. ¶ Note that regular expressions are objects, and have methods. answered Feb 28, 2010 at 15:57 64 var objMap = {"JObject" : ValuesArray}; var json = JSON. Hot Network Questions pdfgrep How to locate the pages that contain multiple strings and print the page numbers? The double forward slash // is a comment in JavaScript, but what does a triple forward slash /// mean? The reason I am asking is the code breaks when I remove a line that has ///. I suspect your problem is elsewhere. That's what the backslashes do. cvs data The forward slash (/) is a special character in regex, necessitating escape. The forward slash / is a special character in regular expressions, because it denotes the beginning and the end of them. It's better to stick with forward slashes ( / ). Dec 30, 2010 · Use a regex literal with the g modifier, and escape the forward slash with a backslash so it doesn't clash with the delimiters. fromCharCode calls are unnecessary. replace() method likereplace('/', ":"); But to my surprise, it only replaced the first occurrence in the string. May 28, 2020 · i'm not very familiar with regex and i need help replacing a string value between the first and second occurrence of forward slash in it.
Your string does not contain any backslashes, but esaped \j, and \t wich is the value for tab. replace(/\\"/g, '"'). doh! Assuming this is always the case, is there a similar way to target the second last forward slash? I should probably do this in another way, I know. Get value of a string after last slash in JavaScript javascript get characters between slashes Javascript: Find index of slash (/) in a string. The JavaScript world is moving fast. Replacing special characters with underscores, etc. As a result, it will remove forward slash from the string. Learn about the Java String Length Method, how it works and how to use it in your software development. I tried using regexp. This is also why a regexp is used instead of just '/' - the substring version of String. Nick Schäferhoff Editor in Chief Below you can find the Javascript cheat sheet in. replace() method likereplace('/', ":"); But to my surprise, it only replaced the first occurrence in the string. Byju's and Swiggy, among the biggest Indian startups, are taking a haircut in their valuations -- at least in the eyes of their backers. Backslash \ is used as an escape character for strings in JavaScript, and in JSON. The predefined characters are: single quote (') double quote (") backslash (\) NULL. doh! Assuming this is always the case, is there a similar way to target the second last forward slash? I should probably do this in another way, I know. replace(/\//g, '\\/'); but it would get the string with the \/. length - 1] === "/"; EDIT: Keep in mind, you would need to check that the string is not null first to keep from throwing an exception. JavaScript replace () method is used for manipulating strings. We are going to use the simplest approach which involves the usage of the regex pattern as well as replace() method. @Calibre2010: You can use a class, as it uses a list of CDATA types, which allow slashes. The plus + matches the preceding item (the forward slash) 1 or more times. pdf as well as in the text. Forward slash is changing to backward slash and forward slash I want to change all slashes into one string and I can't find solution. kent christmas ministry fromCharCode calls are unnecessary. If you want to use a literal backslash, a double backslash has to be used. The forward slash / is a special character in regular expressions, because it denotes the beginning and the end of them. You cannot preserve the "exact" string when you stringify, since parsing a json. The forward slashes / / mark the beginning and end of the regular expression. Jan 1, 2021 · Share this: Forward slash can be replaced in Javascript by using replace () method or split () & join () methods. BTW: These slashes are backward slashes. This last part of the url (after the last forward slash "/") will be different each time. If you want to use a literal backslash, a double backslash has to be used. That's what the backslashes do. Get value of a string after last slash in JavaScript javascript get characters between slashes. For your URL example, if you wanted to add text before the first slash with word characters on either side, you could do. For example, to add a slash to the string "hello", you would use the following code: javascriptconst str = "hello";const newStr = str + "/";console. Jan 10, 2014 · Your string is invalid, but assuming it was valid, you'd have to do: var finalData = str. books about cinderella raw`c:\asd\flkj\klsd\ffjkl`join('/') console. Below is the code tested The need to HTML encode the value is pointless since it would invalidate the HTML. But, most likely a faster and simpler solution is to use your language's built-in string list processing functionality - i ListLast( Text , '/' ) or equivalent function. For example, alert("\\\\") will show a. Remove slashes from string using RegEx in JavaScript How to trim string between slash? 0. It can be greatly simplified if you understand some basic rules. In URLs, special characters like the slash (/) can interfere with the normal parsing of the URL, so they need to be percent-encoded (also known as URL encoded). For some incomprehensible reason, there is a fashion for using lazy-mode regular expressions. As we may recall, regular strings have their own special characters, such as \n, and a backslash is used for escaping\d" is perceived: alert("\d\d. \ is correct in a Windows file path and / is correct in a URI. The escape sequence \uXXXX is part of the language's syntax and represents a single Unicode character. I encountered two issues related to the foregoing, when extracting text delimited by \ and /, and found a solution that fits both, other than using new RegExp, which requires \\\\ at the start. Split string on backslash or forward slash How to get a part of string which separated by forward. 6. This last part of the url (after the last forward slash "/") will be different each time.