var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
How can I remove everything between H
and S
so that the outcome would be ABCDEFGHSTUVWXYZ
?
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.
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.
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, "*");
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; console.log( alphabet.replace(/H.*S/, 'HS') )
Or just:
var alphabet = "ABCDEFGHSTUVWXYZ";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With