Skip to content
v0.1.0latest release21 skills2 categories3 sub-categories22 tested scripts68 reference docsContact us

Text Parsing Functions Reference

Reference for excel-advanced-formulas · 726 lines

Productivity / Excelv1.0.0Updated OCT 20 20264 references1 script

Advanced text manipulation functions including TEXTSPLIT, TEXTBEFORE, TEXTAFTER, and regex functions for Excel 365/2024+.

TEXTSPLIT

Split text string into array using delimiters.

Syntax

excel
=TEXTSPLIT(text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with])

Parameters

  • text: Text to split
  • col_delimiter: Delimiter(s) for columns (or array of delimiters)
  • row_delimiter: Delimiter(s) for rows (optional)
  • ignore_empty: TRUE to skip empty values (default FALSE)
  • match_mode: 0 = case-sensitive (default), 1 = case-insensitive
  • pad_with: Value for missing cells when row lengths differ

Split by Single Delimiter

Space:

excel
=TEXTSPLIT("John Smith Doe", " ")

Returns: {"John", "Smith", "Doe"} as row

Comma:

excel
=TEXTSPLIT("apple,banana,cherry", ",")

Comma-space:

excel
=TEXTSPLIT("apple, banana, cherry", ", ")

Split by Multiple Delimiters

Split by comma OR semicolon:

excel
=TEXTSPLIT("a,b;c,d", {",", ";"})

Returns: {"a", "b", "c", "d"}

Split into Rows and Columns

CSV-like data:

excel
=TEXTSPLIT("a,b,c;d,e,f;g,h,i", ",", ";")

Returns 3x3 array:

text
a  b  c
d  e  f
g  h  i

Ignore Empty Values

With consecutive delimiters:

excel
=TEXTSPLIT("a,,b,,,c", ",")

Returns: {"a", "", "b", "", "", "c"}

Ignore empty:

excel
=TEXTSPLIT("a,,b,,,c", ",", , TRUE)

Returns: {"a", "b", "c"}

Case-Insensitive Split

excel
=TEXTSPLIT("aXbxCxd", "x", , , 1)

Returns: {"a", "b", "C", "d"}

Padding Uneven Rows

excel
=TEXTSPLIT("a,b,c;d,e", ",", ";", , , "-")

Returns:

text
a  b  c
d  e  -

Practical Examples

Parse full address:

excel
=TEXTSPLIT("123 Main St, City, State 12345", ", ")

Split multiline text:

excel
=TEXTSPLIT(A1, , CHAR(10))

Parse key-value pairs:

excel
=LET(
  pairs, TEXTSPLIT("name=John;age=30;city=NYC", ";"),
  MAP(pairs, LAMBDA(p, TEXTSPLIT(p, "=")))
)

Parse CSV cell:

excel
=TEXTSPLIT(A1, ",", CHAR(10), TRUE)

TEXTBEFORE

Extract text before a delimiter.

Syntax

excel
=TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Parameters

  • text: Source text
  • delimiter: String to find
  • instance_num: Which occurrence (default 1, negative counts from end)
  • match_mode: 0 = case-sensitive (default), 1 = case-insensitive
  • match_end: 0 = don't match end (default), 1 = treat end as delimiter
  • if_not_found: Value if delimiter not found (default #N/A)

Basic Examples

First name:

excel
=TEXTBEFORE("John Smith", " ")

Returns: "John"

Before second space:

excel
=TEXTBEFORE("John William Smith", " ", 2)

Returns: "John William"

Instance Number

First occurrence:

excel
=TEXTBEFORE("a-b-c-d", "-", 1)

Returns: "a"

Second occurrence:

excel
=TEXTBEFORE("a-b-c-d", "-", 2)

Returns: "a-b"

From end (last delimiter):

excel
=TEXTBEFORE("a-b-c-d", "-", -1)

Returns: "a-b-c"

Second from end:

excel
=TEXTBEFORE("a-b-c-d", "-", -2)

Returns: "a-b"

Handle Not Found

Default (returns #N/A):

excel
=TEXTBEFORE("abc", "x")

Custom fallback:

excel
=TEXTBEFORE("abc", "x", , , , "Not found")

Return original if not found:

excel
=TEXTBEFORE("abc", "x", , , , "abc")

Case-Insensitive

excel
=TEXTBEFORE("HelloXworld", "x", 1, 1)

Returns: "Hello"

Practical Examples

Extract domain from URL:

excel
=TEXTBEFORE(TEXTAFTER(A1, "://"), "/")

Get file name from path:

excel
=TEXTAFTER(A1, "\", -1)

Protocol from URL:

excel
=TEXTBEFORE("https://example.com/page", "://")

Username from email:

excel
=TEXTBEFORE("user@example.com", "@")

TEXTAFTER

Extract text after a delimiter.

Syntax

excel
=TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Parameters

Same as TEXTBEFORE.

Basic Examples

Last name:

excel
=TEXTAFTER("John Smith", " ")

Returns: "Smith"

After second space:

excel
=TEXTAFTER("John William Smith", " ", 2)

Returns: "Smith"

Instance Number

After first delimiter:

excel
=TEXTAFTER("a-b-c-d", "-", 1)

Returns: "b-c-d"

After last delimiter:

excel
=TEXTAFTER("a-b-c-d", "-", -1)

Returns: "d"

Practical Examples

File extension:

excel
=TEXTAFTER("document.pdf", ".")

Domain from email:

excel
=TEXTAFTER("user@example.com", "@")

Query string from URL:

excel
=TEXTAFTER("https://site.com/page?id=123", "?")

Last folder in path:

excel
=TEXTAFTER("C:\Users\John\Documents", "\", -1)

Combined TEXTBEFORE and TEXTAFTER

Extract middle portion:

excel
=TEXTBEFORE(TEXTAFTER("prefix_value_suffix", "_"), "_")

Returns: "value"

Parse structured string:

excel
=LET(
  text, "Name: John Smith | Age: 30 | City: NYC",
  name_part, TEXTBEFORE(text, " | "),
  name, TEXTAFTER(name_part, ": "),
  name
)

REGEXTEST

Test if text matches a regular expression pattern.

Syntax

excel
=REGEXTEST(text, pattern, [case_sensitivity])

Parameters

  • text: Text to test
  • pattern: PCRE2 regex pattern
  • case_sensitivity: 0 = case-sensitive (default), 1 = case-insensitive

Returns

TRUE if pattern matches, FALSE otherwise.

Basic Patterns

Contains digits:

excel
=REGEXTEST("abc123", "\d")

Returns: TRUE

Starts with letter:

excel
=REGEXTEST("Hello", "^[A-Za-z]")

Returns: TRUE

Ends with number:

excel
=REGEXTEST("Item5", "\d$")

Returns: TRUE

Common Validation Patterns

Email format:

excel
=REGEXTEST(A1, "^[\w.-]+@[\w.-]+\.\w{2,}$")

Phone (US format):

excel
=REGEXTEST(A1, "^\d{3}-\d{3}-\d{4}$")

Phone (flexible):

excel
=REGEXTEST(A1, "^\+?[\d\s()-]{10,}$")

Date (YYYY-MM-DD):

excel
=REGEXTEST(A1, "^\d{4}-\d{2}-\d{2}$")

ZIP code (US):

excel
=REGEXTEST(A1, "^\d{5}(-\d{4})?$")

URL:

excel
=REGEXTEST(A1, "^https?://[\w.-]+\.\w{2,}")

IP address (basic):

excel
=REGEXTEST(A1, "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")

Case-Insensitive

excel
=REGEXTEST("Hello World", "hello", 1)

Returns: TRUE

With Conditional

excel
=IF(REGEXTEST(A1, "^\d+$"), "Valid ID", "Invalid")

REGEXEXTRACT

Extract text matching a regular expression pattern.

Syntax

excel
=REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])

Parameters

  • text: Source text
  • pattern: PCRE2 regex pattern
  • return_mode: 0 = first match (default), 1 = all matches as array
  • case_sensitivity: 0 = case-sensitive (default), 1 = case-insensitive

Extract First Match

First number:

excel
=REGEXEXTRACT("Price: $123.45", "\d+")

Returns: "123"

First word:

excel
=REGEXEXTRACT("Hello World", "\w+")

Returns: "Hello"

Extract All Matches

All numbers:

excel
=REGEXEXTRACT("a1b2c3d4", "\d+", 1)

Returns: {"1", "2", "3", "4"} as array

All words:

excel
=REGEXEXTRACT("Hello, World!", "\w+", 1)

Returns: {"Hello", "World"}

All email addresses:

excel
=REGEXEXTRACT(A1, "[\w.-]+@[\w.-]+\.\w+", 1)

Capture Groups

Extract captured portion:

excel
=REGEXEXTRACT("Name: John", "Name: (\w+)")

Returns: "John"

Multiple groups:

excel
=REGEXEXTRACT("John Smith, 30", "(\w+) (\w+), (\d+)")

Returns array of captured groups.

Practical Examples

Extract price:

excel
=REGEXEXTRACT("Total: $1,234.56", "\$[\d,]+\.?\d*")

Extract hashtags:

excel
=REGEXEXTRACT(A1, "#\w+", 1)

Extract dates:

excel
=REGEXEXTRACT(A1, "\d{1,2}/\d{1,2}/\d{2,4}", 1)

Extract URLs:

excel
=REGEXEXTRACT(A1, "https?://[^\s]+", 1)

Phone numbers:

excel
=REGEXEXTRACT(A1, "\d{3}[-.]?\d{3}[-.]?\d{4}", 1)

Convert to Number

excel
=VALUE(REGEXEXTRACT("Order #12345", "\d+"))

REGEXREPLACE

Replace text matching a pattern.

Syntax

excel
=REGEXREPLACE(text, pattern, replacement, [occurrence], [case_sensitivity])

Parameters

  • text: Source text
  • pattern: PCRE2 regex pattern
  • replacement: Replacement text (can use backreferences)
  • occurrence: Which match to replace (0 = all, default)
  • case_sensitivity: 0 = case-sensitive (default), 1 = case-insensitive

Basic Replacement

Remove all digits:

excel
=REGEXREPLACE("abc123def456", "\d+", "")

Returns: "abcdef"

Replace digits with X:

excel
=REGEXREPLACE("abc123def456", "\d", "X")

Returns: "abcXXXdefXXX"

Replace Specific Occurrence

Replace first match only:

excel
=REGEXREPLACE("a1b2c3", "\d", "X", 1)

Returns: "aXb2c3"

Replace second match:

excel
=REGEXREPLACE("a1b2c3", "\d", "X", 2)

Returns: "a1bXc3"

Using Backreferences

Swap order with $1, $2:

excel
=REGEXREPLACE("Smith, John", "(\w+), (\w+)", "$2 $1")

Returns: "John Smith"

Wrap matches:

excel
=REGEXREPLACE("cat and dog", "\w+", "[$0]")

Returns: "[cat] [and] [dog]"

Practical Examples

Normalize whitespace:

excel
=REGEXREPLACE(A1, "\s+", " ")

Remove special characters:

excel
=REGEXREPLACE(A1, "[^a-zA-Z0-9\s]", "")

Mask credit card:

excel
=REGEXREPLACE(A1, "\d(?=\d{4})", "*")

Format phone number:

excel
=REGEXREPLACE("1234567890", "(\d{3})(\d{3})(\d{4})", "($1) $2-$3")

Clean HTML tags:

excel
=REGEXREPLACE(A1, "<[^>]+>", "")

Normalize date format:

excel
=REGEXREPLACE("12/31/2024", "(\d{2})/(\d{2})/(\d{4})", "$3-$1-$2")

Title case first letter:

excel
=REGEXREPLACE(LOWER(A1), "(?:^|\s)(\w)", UPPER("$1"))

Case-Insensitive Replacement

excel
=REGEXREPLACE("Hello HELLO hello", "hello", "hi", 0, 1)

Returns: "hi hi hi"

Common Regex Patterns

Character Classes

PatternMatches
\dDigit (0-9)
\DNon-digit
\wWord character (a-z, A-Z, 0-9, _)
\WNon-word character
\sWhitespace
\SNon-whitespace
.Any character except newline

Quantifiers

PatternMatches
*0 or more
+1 or more
?0 or 1
{n}Exactly n
{n,}n or more
{n,m}Between n and m

Anchors

PatternMatches
^Start of string
$End of string
\bWord boundary

Groups

PatternPurpose
(...)Capture group
(?:...)Non-capturing group
(?=...)Positive lookahead
(?!...)Negative lookahead

Common Patterns Reference

Use CasePattern
Email[\w.-]+@[\w.-]+\.\w{2,}
URLhttps?://[^\s]+
Phone (US)\d{3}[-.]?\d{3}[-.]?\d{4}
Date (ISO)\d{4}-\d{2}-\d{2}
Time (24h)\d{2}:\d{2}(:\d{2})?
IP Address\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
Hex Color#[0-9A-Fa-f]{6}
Credit Card\d{4}[- ]?\d{4}[- ]?\d{4}[- ]?\d{4}
ZIP (US)\d{5}(-\d{4})?
SSN\d{3}-\d{2}-\d{4}

Combining Text Functions

Parse Complex String

excel
=LET(
  raw, "John Smith <john@example.com> (Manager)",
  name, TEXTBEFORE(raw, " <"),
  email, TEXTBEFORE(TEXTAFTER(raw, "<"), ">"),
  role, TEXTBEFORE(TEXTAFTER(raw, "("), ")"),
  HSTACK(name, email, role)
)

Validate and Extract

excel
=LET(
  text, A1,
  is_valid, REGEXTEST(text, "^\d{3}-\d{3}-\d{4}$"),
  IF(is_valid, REGEXREPLACE(text, "-", ""), "Invalid")
)

Split and Transform

excel
=LET(
  parts, TEXTSPLIT("apple,BANANA,Cherry", ","),
  MAP(parts, LAMBDA(p, PROPER(TRIM(p))))
)

Extract Multiple Patterns

excel
=LET(
  text, "Contact: john@email.com or 555-123-4567",
  email, REGEXEXTRACT(text, "[\w.-]+@[\w.-]+\.\w+"),
  phone, REGEXEXTRACT(text, "\d{3}-\d{3}-\d{4}"),
  HSTACK(email, phone)
)

Error Handling

Safe TEXTSPLIT

excel
=IFERROR(TEXTSPLIT(A1, ","), A1)

Safe TEXTBEFORE/TEXTAFTER

excel
=TEXTBEFORE(A1, "@", , , , A1)

Safe Regex

excel
=IFERROR(REGEXEXTRACT(A1, "\d+"), "No match")

Validate Before Extract

excel
=IF(REGEXTEST(A1, "\d+"), REGEXEXTRACT(A1, "\d+"), "N/A")
More in Excel