aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes multi-line regex match Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "multi-line regex match" Watch "multi-line regex match" New topic
Author

multi-line regex match

Charles Knell
Greenhorn

Joined: Mar 19, 2006
Posts: 25
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

    Joined: May 06, 2004
    Posts: 262
    Try this:
    Charles Knell
    Greenhorn

    Joined: Mar 19, 2006
    Posts: 25
    Thanks for your reply, but it did not produce a match.
    Dave Wingate
    Ranch Hand

    Joined: Mar 26, 2002
    Posts: 262
    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.


    Fun programming etcetera!
    Charles Knell
    Greenhorn

    Joined: Mar 19, 2006
    Posts: 25
    I'm willing to go ugly early, but I still need to find a pattern that matches three consecutive new lines.
    Charles Knell
    Greenhorn

    Joined: Mar 19, 2006
    Posts: 25
    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".

     
    Don't get me started about those stupid light bulbs.
     
    subject: multi-line regex match
     
    Similar Threads
    Regular expression confusion
    regex confusion.
    Regex: Need clarification on two issues
    Need to tokenize a String , but i need to keep what comes between "and"
    Regular expression to take integers out of a string