Regular Expressions

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Regular Expressions

  • Creator
    Topic
  • #48401
    Keith McLeod
    Participant

      I have the following pattern in a file.

      “10185”,,”CARD”

      “188”,”Smith, Bob”,”SRHC”

      “10200”,,”CCC HOSP”

      I would like a regular expression that matches each line pattern.  This is what I was trying.  The number can vary in length on left side.

      regexp — {“[0-9]*”,*,”[A-Z]*”} $test

      Doesn’t work.  I don’t seem to have the multiple occurence of a number down….  Any help is appreaciated…

    Viewing 2 reply threads
    • Author
      Replies
      • #58534
        Anonymous
        Participant

          Keith,

          I do not think in the regular expressions you could search the syntax with double quote.

          Here is a test :

          The regexp would return 1 if the match is found else 0. see the test resultes below.

          Hope this helps.

          -reggie-

          hcitcl>set test “10185”,,”CARD”

          Error: extra characters after close-quote

          hcitcl>set test “”10185″,,”CARD””

          Error: extra characters after close-quote

          hcitcl>set test “10185 , , CARD”

          hcitcl>echo $test

          10185 , , CARD

          hcitcl>regexp — {“[0-9]*”,*,”[A-Z]*”} $test

          0

          hcitcl>echo $test

          10185 , , CARD

          hcitcl>regexp — {[0-9]* ,*, [A-Z]*} $test

          1

        • #58535
          Jamin Gray
          Participant

            I may be misunderstanding your question, but if you’re looking for a regular expression that matches all three of the example lines you list, how about this?

            Code:


            regexp — {”d+”,(”[w ,]+”)?,”[w ]+”} $test

            It matches 1 or more digits enclosed in double quotes followed by a comma, followed by an optional string of word characters/spaces/commas enclosed in double quotes followed by a comma, followed by a string of word characters or spaces enclosed in double quotes.  It returns true for all three of the examples you listed.

            -jamin

          • #58536
            Charlie Bursell
            Participant

              You solution is way too hard for the problem.

              It looks lime you have a CVS (comma separated values) file.

              Download the latest tcllib (tcllib.8, I think).  One of the packages in there is a csv package.  It will return a list of values for each line.  

              Use it, I think you will like it.

              http://sourceforge.net/project/showfiles.php?group_id=12883&package_id=24585&release_id=363503

              To download tcllib.8

              Charlie

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