Insert a Delimiter After Every N Characters in Google Sheets

Published on

If you want to insert a delimiter after every N characters in Google Sheets, one of the most efficient ways is to use the REGEXREPLACE function. This can be helpful in various use cases — such as formatting text strings, preparing data for splitting, or inserting separators into codes or IDs.

Let’s walk through how to use this function effectively.

Why Insert a Delimiter After N Characters in Google Sheets?

Inserting a delimiter into a text string every N characters can help:

  • Split a text after every N characters.
  • Add a space, comma, pipe, or any custom separator at regular intervals.
  • Format data like product codes, IDs, or even strings of characters.

Google Sheets doesn’t have a built-in tool for this specific task, but we can easily do it using a clever REGEXREPLACE formula.

Generic Formulas to Insert a Delimiter After N Characters

Here are two formula patterns you can use:

1. To Insert a Delimiter After Every N Characters

=REGEXREPLACE(A1, ".{n}", "$0,")

Replace n with the number of characters after which you want to insert the delimiter, and replace the comma (",") with your desired delimiter.

2. To Insert a Delimiter After the First N Characters Only

=REGEXREPLACE(A1, "^.{n}", "$0,")

This inserts the delimiter just once — after the first n characters.

We’ll now look at examples to make this clear.

Examples: Insert a Delimiter After Every N Characters in Google Sheets

Let’s say cell A1 contains the following string:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

To insert a comma after every character, use:

=REGEXREPLACE(A1, ".{1}", "$0,")

Output:

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,

If you want to insert the delimiter after every 2 characters, use:

=REGEXREPLACE(A1, ".{2}", "$0,")

Output:

AB,CD,EF,GH,IJ,KL,MN,OP,QR,ST,UV,WX,YZ,

To change the delimiter, simply replace the comma with another symbol. For example, to use a pipe (|):

=REGEXREPLACE(A1, ".{2}", "$0|")

Output:

AB|CD|EF|GH|IJ|KL|MN|OP|QR|ST|UV|WX|YZ|

How to Split a Text String After Every N Characters in Google Sheets

If your goal is to split the text every N characters, you can combine REGEXREPLACE with SPLIT:

=SPLIT(REGEXREPLACE(A1, ".{1}", "$0|"), "|")

This approach inserts a delimiter every N characters and then splits the string using that delimiter.

Split text after every N characters using REGEXREPLACE and SPLIT in Google Sheets

Insert a Delimiter After the First N Characters Only

To insert a delimiter after just the first N characters, slightly modify the formula by adding the caret ^ at the beginning of the regex:

=REGEXREPLACE(A1, "^.{13}", "$0-")

This would insert a hyphen after the first 13 characters.

ABCDEFGHIJKLM-NOPQRSTUVWXYZ

If A1 contains "InfoInspired" and you want to insert a space after the 4th character:

=REGEXREPLACE(A1, "^.{4}", "$0 ")

Output:

Info Inspired

This is a great trick when you need to add a space or any other separator at a specific point in a string.

Can You Insert a Delimiter After N Characters in Numbers?

Yes, but there’s a catch.

If the cell contains a number (e.g., 1256789), using REGEXREPLACE directly will result in a #VALUE! error because the function expects a text value.

Workarounds for Numbers in Google Sheets

  1. Convert the number to text first:
=REGEXREPLACE(TO_TEXT(A1), "^.{3}", "$0-")
  1. Format the cell as plain text:
    Go to Format > Number > Plain Text in the menu.
    Then use the regular REGEXREPLACE formula:
=REGEXREPLACE(A1, "^.{3}", "$0-")

Array Formulas: Insert a Delimiter into Multiple Rows

Want to apply this to a column of text or numbers? Use ARRAYFORMULA.

For numbers:

=ARRAYFORMULA(IF(A1:A="", "", REGEXREPLACE(TO_TEXT(A1:A), "^.{3}", "$0-")))
Array Formula to Insert a Delimiter After the Nth Character in Google Sheets

For text strings:

=ARRAYFORMULA(IF(A1:A="", "", REGEXREPLACE(A1:A, "^.{3}", "$0-")))

These formulas help you insert a delimiter after N characters in Google Sheets across an entire range.

Recap: Use Cases for Inserting Delimiters

  • Format product or employee codes.
  • Break long strings into readable chunks.
  • Prepare data for splitting by inserting a temporary delimiter.
  • Split text after or every N characters using SPLIT.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Top Discussions

More like this

Pivot Table Formatting, Output & Special Behavior in Google Sheets

Pivot Tables in Google Sheets are powerful—but they can get tricky once you move...

Pivot Table Calculations & Advanced Metrics in Google Sheets

When it comes to built-in tools for data analysis and visualization in Google Sheets,...

Google Sheets Pivot Table Tutorial: Basics, Setup, and Date Grouping

The easiest way to summarize, analyze, and report data in Google Sheets is by...

2 COMMENTS

  1. I am using transpose and split by every new line (char(10)) to split to rows a very long text from a single cell. Is there a way to insert a new line break if the line exceeds a certain number of characters (and not breaking a word in two)?

    I am concatenating cells with long text, then splitting to rows (for printing purpose) and I need to have no overflowing cells, and keep the line breaks I already have.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.