Reputation: 1205
I try to detect spaces between HTML-Tags.
In my case:
[...]a lot of code[...]<strong>text with spaces. and dots</strong>[...]a lot of code[...]
my goal is to get:
[...]a lot of code[...]<strong>textwithspaces.anddots</strong>[...]a lot of code[...]
that's it. I tryed something like: (?<=<strong>.*)\s(?=</strong>)
but it don't give me the spaces which I want to delete. It is important, that I only delete these spaces and no other which may be destroying the code
Upvotes: 1
Views: 360
Reputation: 1205
As requested, here is my solution:
set(#scrape, $replace regular expression(#scrape, "</strong>\\s|\\s</strong>|</strong>|<strong>\\s|\\s<strong>|<strong>", ""), "Global")
set(#scrape, $replace regular expression(#scrape, "(?<=<strong>.*?)\\s(?=.*?</strong>)", ""), "Global")
set(#scrape, $replace regular expression(#scrape, ""\\s|\\s"|"", ""), "Global")
Upvotes: 0
Reputation: 67978
import re
x="<strong>text with spaces</strong>"
x=pattern=re.sub(r"\s+","",x)
Upvotes: 1