I have strings for example: "1. Hearing records (Tbr.1.t.4.)" or "23. Appointment details (Tbr.2.t.2.)".
I want to get "Hearing records (Tbr.1.t.4.)" and "Appointment details (Tbr.2.t.2.)".
How can I achieve this with javascript, preferably vanilla? I want to remove all characters (numbers and dots) that appear before the first letter, but after that leave everything unchanged.
Thank you
CodePudding user response:
const cases = ['1. Hearing records (Tbr.1.t.4.)','23. Appointment details (Tbr.2.t.2.)']
const filtered = cases.map((item)=>{
return item.split('.').slice(1).join('').trim()
});
console.log(filtered)
const word = "1. Hearing records (Tbr.1.t.4.)";
console.log(word.split('.').slice(1).join('').trim())
I hope it will work. Cheers :)
CodePudding user response:
I tried to solve this through JS. Here is my code:
let str = '1.Hearing records (Tbr.1.t.4.)';
function deleteToLetter(str) {
let indx = str.indexOf('.')
str = str.slice(indx 1);
return str;
}
console.log(deleteToLetter(str));
CodePudding user response:
Step by step :
- Find first index of the character you are looking for.
- Get substring from string after the index (with some manipulation).
let s = "1. Hearing records (Tbr.1.t.4.)";
let indx = s.indexOf('.');
s = s.substring(indx 2);
console.log(s);
CodePudding user response:
You mean something like that?
let txt = "1. Hearing records (Tbr.1.t.4.)"
let newText = txt.replace(/\d \.\s/g, "");
console.log(newText )