no classification
no tag
no datas
posted on 2024-12-02 22:09 read(970) comment(0) like(10) collect(1)
I use the regex like that
return(\s+([^"\n;]+))?;
in order to match the return statement in obj-c,but when I use it through python like this:
re.sub(r'return(\s+([^"\n;]+))?;',r'{\g<0>}',str(content))
I find that it match like this statement
//please {return
[self funcA];}
and make the code error.How can I deal with it ?
I think the issue is that your regex has \s
that matches any whitespace.
You might want to just match literal spaces or tabs with [ \t]
:
r'return([ \t]+([^"\n;]+))?;'
(demo) or - better:
r'return[ \t]+[^"\n;]*;'
See the regex demo
Author:qs
link:http://www.pythonblackhole.com/blog/article/247239/d638d696336229705825/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!