Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Regular Expressions

St. JimmySt. Jimmy Posts: 3Member
Hey All,

This is more of a regular expressions question than a Java question. I am trying to make a simple SQL statement parser and it seems my regular expression that I use to verify that the select statement is in the form select-from-where isn't working. Here are my example string and regex pattern:

input string: "select A1, B1 from R, S where A4 = rain and A2 = B2;"
regex pattern: "([sS][eE][lL][eE][cC][tT]) [.]+ ([fF][rR][oO][mM]) [.]+ ([wW][hH][eE][rR][eE]) [.]+;"

but it says that the pattern doesn't match the string? :S

Thanks,
Jono

Comments

  • St. JimmySt. Jimmy Posts: 3Member
    Okay I got it to work now. What was wrong is that the sections in the pattern where I want to see what the arguments are should not have the [] since those are meant for options that a single character can be. My new pattern is:

    "([sS][eE][lL][eE][cC][tT]) (.)+ ([fF][rR][oO][mM]) (.)+ ([wW][hH][eE][rR][eE]) (.+);";

    Beauty eh?

    Jono
Sign In or Register to comment.