Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

multi-line regex match  RSS feed

 
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
     
    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.
     
    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
    Boost this thread!