Loading

Extracting Strings Between Keywords Using Formulas

Data pubblicazione: Aug 4, 2026
Descrizione

This article explains how to extract a specific string enclosed by two keywords in a Text or Text Area field in Salesforce. The formula combines the MID, FIND, LEN, and TRIM functions.

Risoluzione

This article answers the question: how do you create a Salesforce formula that extracts the text between two keywords in a Text or Text Area field? Combine the FIND, MID, LEN, and TRIM functions, as shown in the example below.

How to Extract a String Between Two Keywords with a Salesforce Formula

This section explains how to create a formula to extract a specific string enclosed by keywords from data entered in a Text or Text Area field. The formula uses a combination of the FIND, MID, and LEN functions to identify the "starting position" and the "number of characters" for extraction.

Implementation Example for Extracting a String Between Keywords

To extract only the string "IT" between the keywords "【1】" and "【2】" from the following text in a Text Area field (Field1__c), use the formula sample below.

Field value: "【1】IT【2】Salesforce"

Formula Sample for Extracting a String Between Keywords

The following formula returns the text between "【1】" and "【2】" in the Field1__c field, with leading and trailing spaces removed.

TRIM(
  MID(
    Field1__c,
    FIND("【1】", Field1__c) + LEN("【1】"),
    FIND("【2】", Field1__c) - (FIND("【1】", Field1__c) + LEN("【1】"))
  )
)

Role of Each Function in the Formula

The table below describes what each function does in general and what it does in the formula above.

FunctionGeneral RoleSpecific Role in the Above Formula
FINDReturns the position of a specific string within a text string as a number.Identifies the numerical character positions of the keywords "【1】" and "【2】".
LENReturns the number of characters in a text string.Counts the length of the keyword itself to correctly offset the starting position.
MIDReturns a specific number of characters from a text string starting at a specified position.Extracts only the target characters based on the identified start point and length.
TRIMRemoves spaces and tabs from the beginning and end of a text string.Ensures any unnecessary whitespace around the extracted "IT" is removed.

Result of the Formula

The formula above successfully extracts the string "IT" located between "【1】" and "【2】".

Considerations for Using This Formula

  • This formula assumes that each keyword appears only once and that "【1】" always precedes "【2】".
  • If these conditions are not met (for example, the order of the keywords is reversed), the formula may not return the intended result.
  • This is a general configuration example. Please adjust the logic according to your specific business requirements.
Numero articolo Knowledge

005232627

 
Caricamento
Salesforce Help | Article