0
지금까지 전체 문자열 끝에있는 원치 않는 문자 만 제거 할 수있었습니다. 그러나 나는 각 단어의 시작 부분에 그것을 제거하지 않고 각 단어의 끝에 동일한 결과를 얻는 방법을 모른다.정규 표현식을 사용하여 각 단어의 끝에있는 특정 문자를 제거하십시오.
Here 내가 얻은 것입니다.
function removeCharacter(str){
return str.replace(/[!]*$/g, '');
}
console.log(removeCharacter('Hello, my name is Ivan Ivanych.!'));
console.log(removeCharacter("!!Hello there.!!"));
console.log(removeCharacter("Hello,!!! I!! am! Ivan."));
console.log(removeCharacter("!!!Hello,!!! !!I!! !am! Ivan."));
시도'/! (?! \ S)/g' 또는 '/! (?! \ w)/g'. –
다른 생각 :'.replace (/ (\ w)! +/g, "$ 1")'. –
예상되는 결과는 무엇입니까? – Toto