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
1 Correct answer
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.
HTH,
^ _ ^
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,
^ _ ^
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.
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
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,
^ _ ^
Copy link to clipboard
Copied
I meant Dreamweaver search and replace function in general, not the tags.
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,
^ _ ^
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,
^ _ ^
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.
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,
^ _ ^
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.
HTH,
^ _ ^
Copy link to clipboard
Copied
Did the last update I provided work?
V/r,
^ _ ^
Copy link to clipboard
Copied
Yes, works
Thanks
Copy link to clipboard
Copied
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,
^ _ ^

