If I want to match strings on the following form:
%s %i ( %f %f %f ) (%f %f % f)
where
%s is letters, e.g a string
%i a integer, posetiv or negative
%f a float, can be 0 or 0.0,
ex:
"green" 3 (0 0 0) (-0.4 0.00002 0.222) (4.56 -10.3232 2.533)
or
"red" -6 (0.000012 -0.23131 0.2321) (-0.4 0.00002 0.222) (4.56 -10.3232 2.533)
How can a match these with a regular expression, Im using the regcomp/regexec functions in c.
in Java I would use a expression like this:
\"([a-z]+)\"\\s(-*[0-9]+)\\s\\(\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s\\)\\s\\(\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s\\)
this piece of code should do the trick in Java
Code:
public static void main(String[] args) {
StringBuffer buf = new StringBuffer("\"origin\" -1 ( 0 0 0 ) ( -0.4999999404 -0.5000000596 -0.5000000596 )");
StringBuffer parsed;
String exp = "\"([a-z]+)\"\\s(-*[0-9]+)\\s\\(\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s\\)\\s\\(\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s(-*[0-9]*\\.*[0-9]*)\\s\\)";
Pattern p = Pattern.compile(exp);
Matcher m = p.matcher(buf);
while(m.find()){
System.out.println(m.group(0));
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3)+","+m.group(4)+","+m.group(5));
System.out.println(m.group(6)+","+m.group(7)+","+m.group(8));
}
}
can somebody please help me get this to work in c?