Example string:
This is an EXAMPLE SENTENCE, just do give YOU AN Example on Monday, BUT NOT FOR Friday.
Expected output:
This is an Example Sentence, just do give You An Example on Monday, But Not For Friday.
I've tried Propper, but this changes every first letter from every word to uppercase.
CodePudding user response:
I don't think it's possible to change the case using Regular Expressions, here's what you can try instead:
=ARRAYFORMULA(LAMBDA(word,JOIN(" ",IF(EXACT(UPPER(word),word),PROPER(word),word)))(SPLIT(A1," ")))
This formula is SPLIT
ting the sentence by the space " "
to separate each word and uses IF
to check if each word converted to UPPER
case is EXACT
ly the same as the word not converted, if it is, it replaces it with PROPER
casing, otherwise it keeps it as it is. Finally, it JOIN
s the words back together.
CodePudding user response:
Arrayformula
You need to specifiy your range once in a Byrow()
range, in this case A2:A
=ArrayFormula(
BYROW(A2:A, LAMBDA(x, IF(x="",,
LAMBDA(r, TEXTJOIN(" ",1,MAP(r,PROPER(r), LAMBDA(i,a,
IF(REGEXMATCH(i, "\b[A-Z] \b")*1<>1,i,PROPER(a))))))
(SPLIT(x," "))))))
One Cell
=ArrayFormula(
LAMBDA(r, TEXTJOIN(" ",1,MAP(r,PROPER(r), LAMBDA(i,a,
IF(REGEXMATCH(i, "\b[A-Z] \b")*1<>1,i,PROPER(a))))))
(SPLIT(A2," ")))
Used formulas help
ARRAYFORMULA
- BYROW
- LAMBDA
- IF
- TEXTJOIN
- MAP
- PROPER
- REGEXMATCH
- SPLIT