Regular Expression Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karlectomy
    New Member
    • Sep 2007
    • 64

    Regular Expression Issue

    Hi there,

    I am parsing some text files using a buffered reader. I use regular expressions to match different lines to their appropriate cases. I can parse one file fine but when I run the parse on multiple files, I get

    Exception in thread "main" java.util.regex .PatternSyntaxE xception: Unmatched closing ')' near index 3
    view)

    The thing is, I never get it in the same place twice. It will occur in the middle of words and never in the same word twice. I don't know if anyone might have an inkling of an idea on this one...

    here are the patterns I'm using:

    [CODE="JAVA"]
    Pattern origin = Pattern.compile ("Date of origin: .*");
    Pattern review = Pattern.compile ("Last review date: .*");
    Pattern condition = Pattern.compile ("Clinical Condition: .+");
    Pattern variant = Pattern.compile ("Variant \\d+: .+");
    Pattern blank = Pattern.compile ("\\s*");
    Pattern Heading4 = Pattern.compile ("Radiologic Procedure Rating .*");
    Pattern Heading3 = Pattern.compile ("Rating Comments.*");
    Pattern Footer4 = Pattern.compile ("Rating Scale: .+");
    Pattern Footer3 = Pattern.compile ("Appropriatene ss Criteria Scale.*");
    Pattern References = Pattern.compile ("References.*" );
    Pattern PageHeaderStart = Pattern.compile ("An ACR Committee on Appropriateness Criteria and its expert panels have developed criteria for determining appropriate imaging examinations for diagnosis and treatment of specified medical.*");
    Pattern ReferenceStart = Pattern.compile ("\\d+\\Q.\\ E .+");
    [/CODE]
    Wishes,

    Karl
    Last edited by karlectomy; Jan 3 '08, 05:18 PM. Reason: added patterns
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by karlectomy
    I can parse one file fine but when I run the parse on multiple files, I get

    Exception in thread "main" java.util.regex .PatternSyntaxE xception: Unmatched closing ')' near index 3
    view)
    This doesn't make sense. Your code should be parsing each file separately, so if it can parse file1 or file2, it should be able to parse them in succession. The error must be somewhere in the logic where you change from one file to multiple files.

    Comment

    • karlectomy
      New Member
      • Sep 2007
      • 64

      #3
      Originally posted by BigDaddyLH
      This doesn't make sense. Your code should be parsing each file separately, so if it can parse file1 or file2, it should be able to parse them in succession. The error must be somewhere in the logic where you change from one file to multiple files.
      That's what I said... But there is not logic difference. I just call the same function in a for loop over an array of files from the parent directory...

      All of the correct files are in the _files array which I iterate over. and I can run the parse on each file individually.

      It opens several files fine but it will randomly? throw the regex.PatternSy ntaxException: Unmatched closing ')' exception and it only works on the first 7 files... but I think that is an unrelated issue.

      [CODE="JAVA"]

      for(File x: _files){
      try{
      AcrParser acr = new AcrParser(x.get CanonicalPath() );
      acr.parseText() ;
      }catch(IOExcept ion e){
      e.printStackTra ce();
      }

      }
      [/CODE]

      And my Original call to the function:
      [CODE="JAVA"]
      AcrParser acr = new AcrParser("some file.txt");
      acr.parseText() ;
      [/CODE]
      Last edited by karlectomy; Jan 3 '08, 06:37 PM. Reason: re read reply and debugged

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        I hope AcsParser doesn't have any static fields?

        Beyond that, all I can suggest is to write a SSCCE: http://mindprod.com/jgloss/sscce.html

        Comment

        • karlectomy
          New Member
          • Sep 2007
          • 64

          #5
          Originally posted by BigDaddyLH
          I hope AcsParser doesn't have any static fields?

          Beyond that, all I can suggest is to write a SSCCE: http://mindprod.com/jgloss/sscce.html
          THanks for your time,

          I hope its not a simple "hoser at the keyboard error" as my highschool programming teacher used to say...

          Yeah I built it from single file case up to multiple files... I am really frustrated because it seems the exceptions are being thrown at random and that doesn't help with debugging. My only idea is that maybe when comparing a string with a ( or ) in it, the regular expression engine farks up... I am going to try to replace parentheses with something... i don't know what yet.... BAHNAHBAHABAH
          Last edited by karlectomy; Jan 3 '08, 07:30 PM. Reason: thanks given where thanks is due

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            @OP: you only showed us those compiled patterns. How do you use them to match
            and optionally replace parts of the lines you just read from your files?

            kind regards,

            Jos

            Comment

            • karlectomy
              New Member
              • Sep 2007
              • 64

              #7
              I found my problem... THere is a line in one of the files that I am parsing which consists of

              view)

              I am using the string matches function and not the regex engine to compare this line and it is getting all funky dunky on my badunky dunky...

              My regular expressions were not the problem but thanks for the help.

              May all your days be Exception free :)

              Karl

              Comment

              Working...