I can’t find out why my regex does not match a line when using java’s String.matches method – it does match using on online regex tester.
Here is the Java-Code:
line.trim().replaceAll(" +", " ").matches("(const )?[a-zA-Z0-9\\*]*\\ [a-zA-Z0-9\\*]*[,|)]");
and the line that should be matched:
bool fLoad) // somecomment
Does anybody have any ideas why this is so?
matches()means it should match completely, i.e. the whole string fits the RE. Your RE does not allow anything after the ‘)’. Try usingfind()insteadmatches().