Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets regexextract first letter of each word

how do I display the first letter of each word in let's say cell A1:

Example:

A1= Foo bar

A1= Foo

in the first example, I want to display "Fb"

in the second example, I want to see "F"

If A1 = empty I don't want to show anything

I tried this:

=REGEXEXTRACT(A1;"^.")

that shows only the first letter

like image 675
Ralph Schipper Avatar asked Oct 25 '25 15:10

Ralph Schipper


1 Answers

How about this? Please think of this as just one of several answers.

Modified formula:

=IF(A1="","",JOIN("",ARRAYFORMULA(REGEXEXTRACT(SPLIT(A1," "),"\b[\w]"))))
  1. When the cell "A1" is empty and not empty, "" and the first letters of each word are put, respectively.
  2. Split the value to each word using SPLIT.
  3. Retrieve the first letter from each word using REGEXEXTRACT and ARRAYFORMULA.
    • Regular expression of \b[\w] was used.
  4. Join each array using JOIN.

Result:

enter image description here

References:

  • SPLIT
  • REGEXEXTRACT
  • ARRAYFORMULA
  • JOIN

If this was not the result you want, I apologize.

Added:

As an other, it uses LEFT instead of REGEXEXTRACT.

Modified formula:

=IF(A1="","",JOIN("",ARRAYFORMULA(LEFT(SPLIT(A1," ")))))

Reference:

  • LEFT
like image 132
Tanaike Avatar answered Oct 27 '25 04:10

Tanaike