Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multi-line regex match

 
Charles Knell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a file containing the DDL from a database. My goal is to pick it apart and create an XML file representing the structure that I can process further with XSLT.

A typical section I want to capture looks like this:


So the important facts, as I see them, are:
  • I want to start the capture on a line that begins with "CREATE TABLE"
  • I want to stop the capture where there are three consecutive new line characters


  • My regex coding works for me when selecting patterns on a single line. For example, this procedure will correctly print the names of all the tables in the document:


    I have tried this pattern to capture the entire table definition, but the program doesn't print anything after several minutes of running.



    I may have an issue with greedy matching when I want non-greedy matching, but I am rusty on REGEX and anyway, my biggest experience with it was in perl, where things are very different.

    Please, can someone correct my pattern? Thanks
     
    Alan Moore
    Ranch Hand
    Posts: 262
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Try this:
     
    Charles Knell
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for your reply, but it did not produce a match.
     
    Dave Wingate
    Ranch Hand
    Posts: 262
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Could you pre-process your content by:
    1) replacing matches on 3 carriage returns with a symbol that's not commonly used in SQL, say, "^".
    2) remove all remaining carriage returns.

    I've never tried this, but thought it might be a simple (though inellegant) way to solve the problem.
     
    Charles Knell
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm willing to go ugly early, but I still need to find a pattern that matches three consecutive new lines.
     
    Charles Knell
    Greenhorn
    Posts: 25
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    O.K. I'm making progress. This pattern matches exactly three new lines. Because I'm working on Windows, I need both the "\r" and "\n".

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic