• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find and Replace in Files – Add After Start Tag issue

Explorer ,
Jan 18, 2019 Jan 18, 2019

Copy link to clipboard

Copied

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

Views

470

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 24, 2019 Jan 24, 2019

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,

^ _ ^

Votes

Translate

Translate
LEGEND ,
Jan 18, 2019 Jan 18, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 18, 2019 Jan 18, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

Then if you insist on using deprecated code which will eventually make your site obsolete and unusable, my first post should work.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

I meant Dreamweaver search and replace function in general, not the tags.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

That's what I'm talking about.  In the document in question, open Find and Replace, make sure you select current document, and put a checkmark in the box next to "Regular Expression".

In the find area, enter:  (<a[^>]>)(.+)(</a>)

In the replace area, enter: $1<sup>$2</sup>$3

This will go through the document, find all anchor tags, insert <sup> between the opening anchor tag and the text, insert </sup> between the text and the closing anchor tag.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

I should add:  This should work assuming that no anchor tags are malformed (ie, "< a href="file.html">" or "< / a >").

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

I found time to test this.  So far my original recipe isn't working.  I'll let you know when I have the right RegEx.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

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,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 29, 2019 Jan 29, 2019

Copy link to clipboard

Copied

Did the last update I provided work?

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

Yes, works

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 30, 2019 Jan 30, 2019

Copy link to clipboard

Copied

LATEST

Thank you for marking my answer as correct.  I do appreciate it, and I'm sure other users who seek the same as you did will, too.

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines