Non-greedy delete tag

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Non-greedy delete tag

Post 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.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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>)
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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!
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
User avatar
AmigoJack
Posts: 568
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post 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)...?
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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.
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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?
User avatar
Mike Olds
Posts: 226
Joined: Wed Sep 30, 2009 3:27 pm
Contact:

Post 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
Thank you, and
Best Wishes,
Obo
http://buddhadust.net/
check out the What's New? Oblog:
http://buddhadust.net/dhammatalk/dhamma ... ts.new.htm
Post Reply