Reference·MSH Segment·MSH-2
HL7 v2 Reference

Testing HL7 v2 MSH-2: What Encoding Characters Actually Needs to Handle

Jul 27, 2026 · 4 min read
← MSH-1 MSH-3 →

MSH-2 is four characters packed together right after the field separator, and each one quietly controls how every other segment in the message gets split apart — get one wrong and composite fields like patient name or address stop parsing correctly.

Quick answer

MSH-2 is the four-character field immediately after MSH-1 — by convention ^~\& — that defines the component, repetition, escape, and subcomponent separators used throughout the rest of the message.

What each character defines

^
Component separator — splits a field into its parts, e.g. name into last^first
~
Repetition separator — separates multiple occurrences of a repeating field
\
Escape character — flags an escape sequence for special characters inside text
&
Subcomponent separator — splits a component into finer parts when needed

Example

Synthetic example Generated by Synthibase
MSH|^~\&|ADTSYS|HOSP|BILLSYS|HOSP|20260727143000||ADT^A01|MSG00001458|P|2.5.1

The four characters right after the first pipe — ^~\& — are MSH-2, setting the component, repetition, escape, and subcomponent delimiters. Synthetic message — not a real transmission.

Where this trips people up

A patient address or name that legitimately contains one of these delimiter characters — an ampersand in a business name, for instance — has to be escaped using the escape character defined here, and integrations that skip escaping on the way out, or fail to unescape on the way in, end up with corrupted or truncated free-text fields that only surface once real-world data with those characters shows up.

HL7 v2 MSH Explained: Structure, Fields, and Common Mistakes
How to Write EDI Test Cases That Actually Catch Go-Live Failures
How to Test EHR Upgrades Without Touching Production Data
Test escape-character edge cases before they hit production
Synthibase generates synthetic HL7 messages with edge-case characters baked in, so escaping bugs surface in testing instead of on a live feed.
Start free trial →
This page is written independently by Synthibase for testing and informational purposes. It is not an official publication of HL7 International or X12/Washington Publishing Company, and is not a substitute for reviewing the official standard or your trading partner's companion guide. See our Terms of Service for full legal terms.