Skip to content

HL7 v2 escape sequences

When a field value needs to contain a delimiter character literally, HL7 v2 escapes it with the escape character declared in MSH-2 (conventionally \). The five standard sequences are \F\ for the field separator |, \S\ for the component separator ^, \T\ for the subcomponent separator &, \R\ for the repetition separator ~, and \E\ for the escape character itself. \Xdddd...\ carries hexadecimal character data.

\F\Field separator | as data
\S\Component separator ^ as data
\T\Subcomponent separator & as data
\R\Repetition separator ~ as data
\E\Escape character \ as data
\Xdddd...\Hexadecimal character data

Example

On the wire (escaped):   OBX|1|TX|48767-8^Annotation^LN||Referred by A\T\B Cardiology \S\ follow-up in 2 weeks||||||F
As data (unescaped):     Referred by A&B Cardiology ^ follow-up in 2 weeks

The practice name contains a literal & and the note contains a literal ^.
Unescaped, the & would split the value into subcomponents and the ^ into
components, silently changing the message's structure.

Hand-authored illustration of the escape rule on an OBX text field; the segment layout matches engine output, the narrative value is invented to show both sequences.

Validation context

Strict and compatibility validation notes land here with the phase-1 data export.

This answer, in your terminal

pidgeon lookup MSH.2

Wire it into your AI agent:

claude mcp add pidgeon -- npx -y @pidgeonhealth/mcp

Download Post free to browse this reference with generation attached.

HL7® and FHIR® are registered trademarks of Health Level Seven International.

Published by Pattern Engine LLC (Pidgeon Health).

Rendered from the same machine-readable definitions the Pidgeon engine validates against. Hand-authored reference page (phase 1b).