

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to replace before first forward slash - JavaScript?
Let’s say the following is our string with forward slash −
var queryStringValue = "welcome/name/john/age/32"
To replace before first forward slash, use replace() along with regular expressions.
Example
Following is the code −
var regularExpression = /^[^/]+/ var queryStringValue = "welcome/name/john/age/32" var replacedValue = queryStringValue.replace(regularExpression, 'index'); console.log("Original value="+queryStringValue); console.log("After replacing the value="+replacedValue);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo245.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo245.js Original value=welcome/name/john/age/32 After replacing the value=index/name/john/age/32
- Related Questions & Answers
- Split a URL in JavaScript after every forward slash?
- Replace backward slashes with forward slashes - JavaScript
- Replace alphabets with nth forward alphabet in JavaScript
- How to extract string before slash from a vector in R?
- How to replace backward "" slash from a string
- Update all varchar column rows to display values before slash in MySQL?
- MySQL query to replace part of string before dot
- How to replace string using JavaScript RegExp?
- JavaScript regex - How to replace special characters?
- How to Replace null with “-” JavaScript
- How to replace leading zero with spaces - JavaScript
- How to Write accounting for forward contracts?
- Java Program to replace the first 10 characters in JTextArea
- Replace first occurrence of a character in Java
- How to replace only the first repeated value in a string in MySQL
Advertisements