To remove non-alphabetic characters and capitalize the first letter of each word, you can utilize a regular expression in conjunction with the replace
method within your pipe.
Start by using:
str = str.replace(/[^\w\s]/gi, "")
This code snippet will eliminate all non-alphabet characters from the string.
Next, you can apply:
str = str.replace(/\b\w/g, (str) => str.toUpperCase())
This piece of code will convert any lowercase initial character next to a word boundary (like a space) into uppercase.
You can combine these steps like this:
let str = "@!₪ test stri&!ng₪";
str = str.replace(/[^\w\s]/gi, "") // Remove non-word characters
.trim() // Eliminate leading and trailing spaces
.replace(/\b\w/g, (s) => s.toUpperCase()) // Capitalize the first letter of each word
console.log(str);