Hello!
I want to parse some C source files and find all strings ("foo").
Something like that works
String line = "myfunc(\"foo foo foo\", \"bar\");";
System.out.println(line);
String patternStr = "\\\"([^\"]+)\\\"";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher("");
String s;
if(line.matches(".*"+patternStr+".*"))
matcher.reset(line);
while(matcher.find()) {
System.out.println(" FOUND "+matcher.groupCount()+" groups");
System.out.println(matcher.group(1));
}
Until there are no "escape quoted strings" like
String line = "myfunc(\"foo \\\"foo\\\" foo\", \"bar\");";
I don't know how to create expression in Java like "without \" but with \." I've found something simmilar for C here http://wordaligned.org/articles/string-literals-and-regular-expressions
Thanks in advance.