Regular Expression Help

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Regular Expression Help

  • Creator
    Topic
  • #50712
    Alka Sharma
    Participant

    Hi Everyone,

    I am looking for some help to pattern match a string and extract accession number from a HL7 message.

    My message looks like this:

    MSH|^~&|RAD|UCHC|||200903111204||ORU|RMS|P|2.3||

    PID|1|000T99000789|000009002872|000000014701|TEST^JAPAN^^^||196604050000|F|

    PV1||O|IC2^IC2^^UCHC||||008033^MANGER MD^THOMAS M^|008320^MENOUTIS MD^JOHN|^^|ORA|||||N^N^U||008033^MANGER MD^THOMAS M^||000000014701||||||||||||||||||||UCHC|

    OBR||00001               ^001            |100114|ULT4280033 ^US ABDOMEN COMPLETE             |||200903101042|||DMC|||||^^^ |008033^THOMAS M MANGER MD||||||200903111204|||||1^^^^^R^^ROUTINE|||||999991&DEFAULT&DOCTOR&&&|

    NTE|||Test change prelim then final

    OBX|1|TX|ULT0033GDT||ULTRASOUND REPORT~***Final Report***~~ULT 0033 – US ABDOMEN COMPLETE  (A#:100114,03/10/2009)~INDICATIONS:  Test change prelim then final~~RESULT:  ~The liver is normal in size and echogenicity.

    I am searching for (A#: and the next set of numbers before the comma is the accession number that I need to pull out.

    This is what I have so far:

    set msgHeader [string range $msg 0 8]

    set msgTail [string range $msg 9 end]

    regexp {[(A#:]} $msgTail match x

    echo “Accession” $x

    Thanks,

    Alka…

Viewing 3 reply threads
  • Author
    Replies
    • #67210

      Try this:

      set var “US ABDOMEN COMPLETE [code]set var “US ABDOMEN COMPLETE

      -- Max Drown (Infor)

    • #67211
      Alka Sharma
      Participant

      Thanks! It worked but Can you explain the expression

      (d+?),

      Alka…

    • #67212

      alka sharma wrote:

      Thanks! It worked but Can you explain the expression

      (d+?),

      Alka…

      Sure! The parens capture the match. The d means match on a digit (number). The + means 1 or more. And the ? means make the match non-greedy. Basically, the ? means to match up to the first comma found and then stop. And the comma is a literal comma. I used the “(A#” and the “,” as the “book ends” for the regexp match.

      -- Max Drown (Infor)

    • #67213
      Grady Stephens
      Participant

      Code:


      set q [ regexp {(.*(A#:)([0-9]*)(,.*)} $p match1 match2 match3 match4]
      echo $match3

Viewing 3 reply threads
  • The forum ‘Cloverleaf’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10