Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6529765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:40:28+00:00 2026-05-25T09:40:28+00:00

Im trying to parse a SQL table creation script in Java. Ive currently got

  • 0

Im trying to parse a SQL table creation script in Java.

Ive currently got the following pattern:

Pattern p = Pattern.compile("(.+)([ ]+)(.+)([ ]+)(.+)");

i.e a group of any chars (column name), followed by one or more spaces, followed by another group of chars (column type), followed by one or more spaces, followed by any number of chars (i.,e not null etc).

And this is used by the following code:

Matcher m = p.matcher(field);
if(m.find()){
    String column = m.group(1).trim();
    String type = m.group(3).trim();
    String clauses = m.group(5).trim();
}

And yet when I run this on:

firstColumn         varchar(4)   not null,

The first group is:

firstColumn         varchar(4)

I would expect the three extracted fields to be firstColumn, varchar(4) and not null respectively.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:40:29+00:00Added an answer on May 25, 2026 at 9:40 am

    (.+) will consume as much as possible. To make it consume as little as possible, change it to (.+?).

    Try something like this:

    String input = "firstColumn         varchar(4)   not null,";
    
    Pattern p = Pattern.compile("(.+?)\\s+(.+?)\\s+(.*)");
    Matcher m = p.matcher(input);
    
    if (m.find()) {
        System.out.println(m.group(1));
        System.out.println(m.group(2));
        System.out.println(m.group(3));
    }
    

    Output:

    firstColumn
    varchar(4)
    not null,
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am trying to parse a string into a java.sql.date Here is what
Trying to parse an SQL string and pull out the parameters. Ex: select *
Trying to parse an HTML document and extract some elements (any links to text
I'm trying to parse an INI file using C++. Any tips on what is
I have been trying to parse Java exceptions that appear in a log for
I'm trying to write an sql function in Postgresql that will parse a file
I have the following SQL query: SELECT DISTINCT ProductNumber, PageNumber FROM table I am
I'm trying to use SQL Server Integration Services (SSIS) to parse an XML file
I'm trying to contruct a parser in scala which can parse simple SQL-like strings.
I am trying to parse the below xml in sql server to get all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.