News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

no datas

How to make the regexp ignore a new line in python?

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 ?


solution


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



Category of website: technical article > Q&A

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.

10 0
collect article
collected

Comment content: (supports up to 255 characters)