Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Parsing using regular expression
Joined: Dec 09, 2010
Dec 23, 2010 02:53:33
I need to parse a formula which can have comments. A valid formula will be something like this.
B = rescale(A,'monthly') +33 ; 'this is a comment
The formula should end with semicolon ";" and a comments can start with single quote(').
If a formula does not end with semi colon then i should throw an Exception (Syntax error)
Invalid formula :
B = rescale(A,'monthly') +33 'this is a formula which does not terminate with semicolon
I need to strip the 'this is a comment in the above example.
I tried with the regular expression like this ['](.*) to strip but it also strips the 'monthly') +33
Can anybody help me in doing this using regular expression?
Some of the valid example of formula in my project
B = abs(A);
A = 2;
Thanks in advance
Joined: Oct 27, 2005
Dec 23, 2010 03:12:41
Regular expressions are a bad tool for parsing like this. You need a proper parser, and that involves writing a grammar that specifies what is and what isn't allowed. JavaCC or ANTLR can be used for creating this parser.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions
How To Answer Questions
subject: Parsing using regular expression
Help with Errors
Struts 2 Integer Validation not working
Generate a string that matches a regular expression
confused with generics
Examlab generics question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013