Two Regular Expression Questions

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Two Regular Expression Questions

  • Creator
    Topic
  • #50168
    Jared Parish
    Participant

    I have been working on the TCL procedure that could be drastically reduced in code if I could do variable substitution in the expression. Is that possible?  Also, I’m having trouble with, or don’t understand how the regexp -all option works.  My expression: regexp -nocase -all -line — {OBR|(.*?|){3}(.*?)^(.*?)^} $msg match v1 msgCategory msgProcedure

    When I use the above regexp I get the second OBR, if I remove the “-all” option I get the first OBR when I run it again the message:

    Quote:

    MSH|^~&||.|||200805221602||ORM^O01|ADTOE 2 4.2.1420|D|2.4|||AL|NE

    PID|1||350000^^^^MR~514-12-5544^^^^SS~35^^^^PI||HULBERT^TEST562^^^^^L||19700203|F||C|801 GRAVES LANE^^FINDLAY^OH^45840^^^^HAN||419-422-7471^^^^PRN|419-422-3437^^^^WPN||S|LUT|000000414

    PV1|1|I|5NU^P5100^01|U|||CONJL^CONNER^JENNIFER^LEA^^^MD|||5NU||||RP|||CONJL^CONNER^JENNIFER^LEA^^^MD|IN||L|||||||||||||||||||.||ADM|||200804021422

    ORC|NW|||||N|||200805221602|DP.AFD||||||||FYMISWS32.2

    OBR|1|EKG20080522-0001.||EKG1^EKG2^ELECTROCARDIOGRAM||200805221601||||||OEISO1^ISOLATION:||||CONJL^CONNER^JENNIFER^LEA^^^MD|||||||||||^^^^^R

    OBR|2|EKG20080522-0002.||EKG3^EKG4^ELECTROCARDIOGRAM||200805221603||||||OEISO1^ISOLATION:||||JOHDD^JOHNSON^DONALD^DEAN^^^DO|||||||||||^^^^^R

    OBX|1|TX|OEEKADM^SDS OR ADM?||ADM

    OBX|2|TX|OEEKD^IS PATIENT ON DIGOXIN OR QUINIDINE?||NO

    OBX|3|TX|OEEKFDR^FAMILY PHYSICIAN:||TEST

    OBX|4|TX|OEEKPRE^PRE-OP, DATE OF SURGERY?||T

    OBX|5|CE|OEPEROR^PHYSICIAN TO READ?||MILLS, SD^MILLS, SD

    ZMN|

    I thought by using the all option I would get a list of matches in the variable…?

    Thanks,

    - Jared Parish

Viewing 0 reply threads
  • Author
    Replies
    • #65086
      Charlie Bursell
      Participant

      If you want a list you need to use the inline option, not the line option.  The line option makes ^ and $ newline aware.

      When using the -inline -all option wit an expression such as yours you must be aware that the list will consiste of sublists for each set of parenthesis as well as the full match.

      foreach {match v1 msgCategory msgProcedure} [regexp -all -inline —

                             {OBR|(.*?|){3}(.*?)^(.*?)^}]   {

            echo FULL MATCH: $match

            echo Parenthis1: $vi

            echo Parenthis2: $msgCategory

            echo Parenthis3: $msgProcedure

      }

      This. of course, assumes a valid expression  ðŸ™‚

Viewing 0 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

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