Advertisement
nicuf

strange situation

Apr 4th, 2022
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hi, I'm facing a strange situation. These FIND and REPLACE do not work. That is, finding works, but replacing does not work.
  2.  
  3. In these 3 situations, I have to replace an annuit regex with (empty space). See that '' there
  4. If at re.findall I put any simple regex, for example an html tag <div> then the replacement is done perfectly.
  5. But if it is a different kind of regex, such as the ones below, the replacement is no longer done. I mean nothing happens ...
  6.  
  7.  
  8. if len(re.findall('(?!<p>).+?(?<!</p>)$', page_text)) != 0:
  9.   page_text = re.sub('(?!<p>).+?(?<!</p>)$', '', page_text)
  10.   counter_img += 1
  11. OR
  12.  
  13. if len(re.findall('^\s+</p>', page_text)) != 0:
  14.   page_text = re.compile(r'', page_text)
  15.   counter_img += 1
  16.  
  17. OR
  18.  
  19. if len(re.findall('\n\s*', page_text)) != 0:
  20.   page_text = re.sub('\n\s*', '', page_text)
  21.   counter_img += 1
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement