Skip to main content
January 18, 2019
Answered

Find and Replace in Files – Add After Start Tag issue

  • January 18, 2019
  • 1 reply
  • 1071 views

Hi,

I am trying to use Find and Replace tool to add a tag after another start tag, namely, I want to add <sup> tag after start tag <a>.

As a result, however, Dreamweaver inserts <sup></sup> pair. I don't want it because I have a content inside the <a> tag and I want to use another find and replace tour (Add Before Closing Tag option) to add a </sup> before closing </a>. So that I embrace the content of <a> with <sup>.

I disabled automatic tag closing in Dreamweaver but this doesn't help. Would appreciate any hints how to resolve this annoying behavior.

Peter

This topic has been closed for replies.
Correct answer WolfShade

GOT IT!    I forgot to add a space to the second backreference.

Enter this in the "FIND" area:  (<a[^>]+>)([\w ]+)(<[^>]+>)

Enter this in the "REPLACE" area: $1<sup>$2</sup>$3

The parenthesis are backreferences (related to $1, $2, $3) so you're taking the first backreference, following it with <sup>, then adding the second backreference, following it with </sup>, then appending the third backreference to that.

HTH,

^ _ ^


UPDATED:  That didn't allow for punctuation.  SMH.

(<\s*a[^>]+>)([!"#$%&'()*+,-.\/:;=?@[\]^_`{|}~|\w| ]+)(<\s*[^>]+>) is what you put in the FIND if you need to include punctuation.

RegEx Tester

HTH,

^ _ ^

1 reply

WolfShade
Legend
January 18, 2019

I think you need to use RegEx to do that.  Just off the top of my head, something _like_:

FIND: (<a[^>]>)(.+)(</a>)  <!--- the parenthesis are back references --->

REPLACE: $1<sup>$2</sup>$3

This _should_ insert <sup> between the opening anchor tag and the text, and </sup> between the text and the closing anchor tag.

UNTESTED.

HTH,

^ _ ^

WolfShade
Legend
January 18, 2019

But I must say that this is old-school and should be avoided.  It would be easier (and better) to apply CSS formatting to all anchor tags.

V/r,

^ _ ^

UPDATE: According to MDN, it would be better to use CSS for what you are trying to do.

January 24, 2019

Dear WolfShade​,

thank you for your remarks on that. Yes, applying styles should be easier here. Anyways, the behavior I mention in original post should be somehow addressed.

Peter