Page 1 of 1
Non-greedy delete tag
Posted: Sun Nov 17, 2019 3:39 pm
by Mike Olds
Hello,
This should be simple, but is beyond me:
I need to eliminate the tag:
<span class="mozp"></span>
surrounding anything:
<span class="mozp">Tath�gata single word or even paragraph with <br /></span>
Any help much appreciated.
I did a search and there is mention that this is not possible in TextPad, but is possible in Wild-edit which I also have.
Posted: Sun Nov 17, 2019 10:43 pm
by ben_josephs
Do you mean you want to remove the entire span element, that is, the start tag and end tag and everything in between?
If so, try
<span\b.*?</span>
If a span element may extend over more than one line, try
<span\b[\s\S]*?</span>
or
(?s:<span\b.*?</span>)
Posted: Mon Nov 18, 2019 12:05 pm
by Mike Olds
Thanks Ben! Yes I wish to eliminate the tag and preserve the contents and it is possible the tag could extend over more than one line.
I'll give this a shot later and get back one way or the other.
You are a real asset to Helios! So many years you have devoted to helping people on this board!
Posted: Mon Nov 18, 2019 1:12 pm
by ben_josephs
Thank you. You're welcome.
These are tags:
<span>
and
</span>
This is an element:
<span> content </span>
Do you want to remove the tags and keep the content? If so, search for
</?span\b[^>]*>
and replace with nothing.
Posted: Mon Nov 18, 2019 1:48 pm
by Mike Olds
Hello Ben,
I see I must be more specific as to what I need.
This is the tag I need to delete:
<span class="mozp"> xxx </span>
keeping the element xxx.
your </?span\b[^>]*>
captures all span tags which goes too far.
Posted: Mon Nov 18, 2019 2:55 pm
by ben_josephs
<span class="mozp"> xxx </span>
is an element, not a tag.
xxx
is content, not an element.
If I search using the regex
</?span\b[^>]*>
in the element
<span class="mozp"> xxx </span>
and replace each match with nothing, what remains is the content
xxx
(with a space at each end).
If that is not the result you want please explain what is.
Posted: Mon Nov 18, 2019 3:14 pm
by AmigoJack
Most likely he doesn't want to delete any SPAN element, but only those which exactly look as pictured (i.e. with that CLASS attribute)...?
Posted: Mon Nov 18, 2019 4:03 pm
by Mike Olds
Hello,
Yes, Amigo has stated the problem correctly.
I want to delete exactly this:
<span class="mozp"></span>
Only this specific tag; not all span tags.
while leaving the content inside the tag as is.
The regex supplied deletes the front <span class="mozp"> but leaves the content AND the close </span>
This is to be done on multiple files with multiple instances likely in most files where it occurs. So I am assuming this is a job for WildEdit.
Posted: Tue Nov 19, 2019 9:15 am
by ben_josephs
The regex
</?span\b[^>]*>
matches opening tags and closing tags. Perhaps you included a space at the end of it.
If the opening tags you are concerned with all look exactly like this
<span class="mozp">
then try searching for
<span class="mozp">([\s\S]*?)</span>
or
(?s:<span class="mozp">(.*?)</span>)
and replacing with
$1
Posted: Tue Nov 19, 2019 2:14 pm
by Mike Olds
Hello Ben,
Both of those appear to work, but with \1 rather than $1 for the replacement.
I have tried these on both the test window and on a real html file.
I confess: I spent several hours trying to make these work and failed because: 1. the sample I used for testing used <p class="mozp"> (another tag I was looking for previously; and
2. the html file I was testing on lacked a header and footer. Just saved a text file as html so the content was apparently not recognized in some way.
Many thanks for your help here, and apologies all around for my confusion.
PS: Like some others recently, when pressing 'submit' I get DEBUG MODE but the post seems to go up eventually.
Posted: Tue Nov 19, 2019 3:51 pm
by ben_josephs
You wrote:test window
You must be using WildEdit. My suggestion works in TextPad 8, which uses (more or less) the same regex package.
You wrote:with \1 rather than $1 for the replacement
Have you been tinkering with the options?
Posted: Tue Nov 19, 2019 4:23 pm
by Mike Olds
Hello Ben,
Tinkering with options in WE. Yes. I normally have this set to the PERL syntax, but with all the failures I used all three for each.
Aside from the syntax options I didn't alter any other options.
PS: Again:
DEBUG MODE
Line : 185
File : smtp.php