java - Regular expression to reduce spaces between function parameters -


i have program i'm trying compare 2 files.

file 1:

void function( col1,                col2,                col3 ) 

file 2:

void function(col1,col2,col3) 

what regexp should use remove spaces , enter between ( , ) since want reduce space between brackets , not other place in code.

this problematic. pure java regex solution have compromise because correctly assess question "are between parentheses?" requires (in worst case, depending on input) handle nested parentheses, text within strings or comments should not modified , possibly other edge conditions.

keeping in mind, simplistic solution works on example @ least (and assumes doesn't have handle nested parentheses, comments or strings, , doesn't have check whether parentheses belong function definition), be

string result = subject.replaceall("\\s+(?=[^()]*\\))", ""); 

this matches , replaces whitespace iff next parenthesis after closing parenthesis.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -