Regular Expressions 101

Community Patterns

HL7 Locate message using fields from two segments.

0

Regular Expression
ECMAScript (JavaScript)

/
PV1\|(?:[^\|]*\|){18}1703000105\|(?:[^\|]*\|){31}CO
/
g

Description

This regex uses non capturing groups to start the match on the first field and then continue to match second field.

SEGMENT|(?:[^|]|){<POSITION1>}<value1>|(?:[^|]|){<POSITION2>}<value2>

SEGMENT is the first segment that has field to match on <POSITION1> is the zero based count of the field in first segment <value1> is the value to match on in the field in first segment. <POSITION2> is the zero based count of the fields from POSITION1 to field in segment of second field <value2> is the value to match on in the field in the second segment

Example Searching for message with PV1-19 of 1703000105 and ORC-1 of CO, where PV1 has 50 fields and is followed by ORC segment PV1|(?:[^|]|){18}1703000105|(?:[^|]|){31}CO

Submitted by Jo5eph - 3 years ago