nicuf

ciudat

Apr 4th, 2022
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. salut, ma confrunt cu o situatie ciudata. Aceste FIND and REPLACE nu merg. Adica find merge, dar replace nu merge.
  2.  
  3. In aceste 3 situatii, trebuie sa inlocuiesc un anuit regex cu (spatiu gol). Vezi acolo acel ' '
  4. Daca la re.findall as pune orice regex simplu, de exemplu un html tag <div> atunci se face inlocuirea perfect.
  5. Dar daca este un alt gen de regex, cum sunt cele de mai jos, inlocuirea nu se mai face. Adica nu se intampla nimic...
  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.  
Add Comment
Please, Sign In to add comment