How can i get |ADT^A05|
out of
"MSH|^~\&|PHTADT09|ABC|DADIST00|ABC|20120425152829|rcalini1|ADT^A05|20429208851634|P|2.1|560"
I have tried this but not working
"|([A-Z]{3})^([A-Z]{1})([0-9]{2})|"
match() function of re in Python will search the regular expression pattern and return the first occurrence. The Python RegEx Match method checks for a match only at the beginning of the string. So, if a match is found in the first line, it returns the match object.
To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.
$ means "Match the end of the string" (the position after the last character in the string).
I don't think you need Regex when there is a separator char like |
var adt = text.Split('|')[8];
See the definition of HL7 format
Each segment in a message is divided into composites, or fields, and the fields are separated by pipe characters ('|')
You need to escape |
and ^
, as those are special characters in a Regex.
@"\|([A-Z]{3})\^([A-Z]{1})([0-9]{2})\|"
Or if you don't like verbatim literals:
"\\|([A-Z]{3})\\^([A-Z]{1})([0-9]{2})\\|"
Note that verbatim literals (using @
before the opening quote) make regexes SIGNIFICANTLY more readable (and more portable -- now you can just copy/paste that regex somewhere else). You should always use verbatim literals with regex strings unless you have a very good reason to do otherwise.
Put backslashes before certain characters: |
and ^
.
\|([A-Z]{3})\^([A-Z]{1})([0-9]{2})\|
Edit: My favorite site ever - http://regexpal.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With