Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace/remove everything between two characters [duplicate]

var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 

How can I remove everything between H and S so that the outcome would be ABCDEFGHSTUVWXYZ?

like image 333
UserIsCorrupt Avatar asked May 21 '12 17:05

UserIsCorrupt


People also ask

How does. Replace work in regex?

To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring. The string 3foobar4 matches the regex /\d. *\d/ , so it is replaced.

How do I get rid of between strings?

Use the deleteCharAt Method to Remove a Character From String in Java. The deleteCharAt() method is a member method of the StringBuilder class that can also be used to remove a character from a string in Java.

How do you replace text between two characters in Java?

Using replaceAll() The first parameter takes in a regular expression while the second takes in a string with the replacement value. String start = "\\{"; String end = "\\}"; String updatedUrl = url. replaceAll(start + ". *" + end, "*");


1 Answers

var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; console.log(  alphabet.replace(/H.*S/, 'HS')  )

Or just:

var alphabet = "ABCDEFGHSTUVWXYZ"; 
like image 127
Paul Avatar answered Sep 28 '22 03:09

Paul