It could be any string, it should match only the UPPERCASE part and change to lowercase, for example:
"It's around August AND THEN I get an email"
become
"It's around August and then I get an email"
as you can see the word It's
, August
and I
should be ignored
The toLowerCase() method converts a string to lowercase letters. The toLowerCase() method does not change the original string.
This can be done easily using regular expressions. In a substitute command, place \U or \L before backreferences for the desired output. Everything after \U , stopping at \E or \e , is converted to uppercase. Similarly, everything after \L , stopping at \E or \e , is converted to lowercase.
For example, the replacement pattern $1 indicates that the matched substring is to be replaced by the first captured group.
Use /\b[A-Z]{2,}\b/g
to match all-caps words and then .replace()
with a callback that lowercases matches.
var string = "It's around August AND THEN I get an email",
regex = /\b[A-Z]{2,}\b/g;
var modified = string.replace(regex, function(match) {
return match.toLowerCase();
});
console.log(modified);
// It's around August and then I get an email
Also, feel free to use a more complicated expression. This one will look for capitalized words with 1+ length with "I" as the exception (I also made one that looked at the first word of a sentence different, but that was more complicated and requires updated logic in the callback function since you still want the first letter capitalized):
\b(?!I\b)[A-Z]+\b
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