Thursday, 15 January 2015

regex - Spaces in Python Regular Expressions -



regex - Spaces in Python Regular Expressions -

i writing python script search entire .c or .h file , find function definitions can create slight edits. find of function definitions trying utilize regular expressions.

what have is:

"r'\w+?\s+?\w+?\s*?\(.*?\)[\n\s]*?{"

the problem logic take if statements in cases. example:

else if(//herpderp){}

it because \s includes \n. sense wouldn't have issue if had look spaces instead of whitespace, can't test theory out seems there no \(insert letter here) simple space.

so there problem. if have advice on how prepare regular expression, or if there improve way of writing script in general please allow me know.

a single space can matched using single space, same way you'd match other character isn't metacharacter:

"r'\w+? +?\w+? *?\(.*?\)\s*?{"

the ' +?' sequence matches only 1 or more spaces, non-greedily. replaced [\n\s] \s \n included already.

you can expand character class more types of whitespace:

[ \t]

which match space or tab.

python regex spaces

No comments:

Post a Comment