# Read HL7 delimiters and field positions

Inspect MSH numbering, repeated fields, custom separators and preserved escape sequences with a synthetic HL7 v2 message.

Workspace 0.2.2 · Analyzer 0.1.0, formatter 0.1.0, checker 0.1.0 · Updated September 14, 2026

[Read this guide as HTML](https://hl7tools.io/guides/hl7-delimiters.html) · [Open HL7 analyzer](https://hl7tools.io/hl7-message-analyzer.html)

## Start with the header

Open the [HL7 Message Analyzer](https://hl7tools.io/hl7-message-analyzer.html) and paste the synthetic message below. It is an inspection fixture, not a complete clinical message or proof of conformance.

`MSH-1` is the field separator itself. `MSH-2` contains the encoding characters; `MSH-3` is the sending application. Counting every pipe-separated item as an ordinary field shifts the header. The [HL7 MSH reference](https://hl7.org/fhir/uv/v2mappings/ConceptMap-segment-msh-source-to-provenance.html) identifies those positions.

```hl7
MSH|^~\&|SYNTHETIC|LOCAL|RECEIVER|LOCAL|202609140900||ADT^A01|GUIDE-001|T|2.5.1
PID|1||SYN-001^^^LOCAL^MR~SYN-002^^^OTHER^MR||EXAMPLE^SYNTHETIC
NTE|1||Encoded separator: \F\
```

## Inspect a repeated field

Choose `PID`, then `PID-3`. With these delimiters, `~` separates repetitions, `^` separates components and `&` separates subcomponents. Empty components still occupy positions: the second identifier has `OTHER` in component 4. Expected observations:

```text
MSH-1: |
MSH-2: ^~\&
MSH-3: SYNTHETIC
PID-3 repetitions: 2
PID-3[2].4: OTHER
NTE-3: Encoded separator: \F\
```

In module code, call `inspectField(segment, 3)` with the original segment returned by `analyzeHL7`. Its one-based paths describe repetitions, components and subcomponents. Re-analyze a serialized or cloned result before inspecting it.

## Read separators from the message

The analyzer accepts distinct visible ASCII punctuation separators. This equivalent inspection fixture declares a field separator of `*`; MSH-2 declares component, repetition, escape and subcomponent separators in that order.

```hl7
MSH*$%!@*SYNTHETIC*LOCAL*RECEIVER*LOCAL*202609140900**ADT$A01*GUIDE-002*T*2.5.1
PID*1**SYN-001$$$LOCAL$MR%SYN-002$$$OTHER$MR**EXAMPLE$SYNTHETIC
```

```text
Delimiters: field=* component=$ repetition=% escape=! subcomponent=@
PID-3 repetitions: 2
PID-5[1].1: EXAMPLE
```

## Keep encoding and transport limits in view

- Escape text remains encoded: `\F\` stays `\F\`. Paired escapes protect embedded delimiters from splitting; the analyzer does not decode escapes or check their full grammar. Unmatched escapes produce a warning.
- A fifth MSH-2 truncation character is retained with a warning; truncation semantics are not interpreted.
- One message with CR, LF or CRLF breaks is accepted, including a single MLLP frame. Multiple messages, batch wrappers and prefixed log text are rejected.
- Copy and Download use normalized message text: supported framing and blank lines are removed, segments use CR, and one final CR is added. This does not preserve original transport bytes.
- Limits are 1 MiB of UTF-8 input, 2,000 segments and 50,000 structural parts. Header checks and common field labels do not establish message structure, datatype, terminology or profile conformance.

All examples are synthetic. [Browse all developer guides](https://hl7tools.io/guides.html).
