7

I'm trying to replace the part the text with the same text and some extra, example:

Initial text

<href="../doc/d5807346.pdf" class="document">3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE</a></div><div style="clear:both;"></div>

After

<href="../doc/d5807346.pdf" class="document" download="3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE">3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE</a></div><div style="clear:both;"></div>

I'm using in Notepad++ the following Regex:

  • Find: ((?<=class="document">).*?(?=<))
  • Replace with: download="\1">\1

End result is not what I'm expecting, note the > between class="document" and download :

<href="../doc/d5807346.pdf" class="document"> download="3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE">3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE</a></div><div style="clear:both;"></div>

I'm stuck on trying to figure out how to prevent that.

2 Answers 2

19
  • Ctrl+H
  • Find what: (class="document")>([^<]+)
  • Replace with: $1 download="$2">$2
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

(class="document")      # group 1
>                       # literally >
([^<]+)                 # group 2, 1 or more any character that is not "<"

Replacement:

$1              # content of group 1 + a space
download="      # literally
$2              # content of group 2
">              # literally
$2              # content f group 2

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

  1. Find: (?:class="document">)([^<]*)
  2. Replace (corrected): class="document">download="$1">$1

Tested in N++

Before: <href="../doc/d5807346.pdf" class="document">3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE</a></div><div style="clear:both;"></div>

After: <href="../doc/d5807346.pdf" class="document">download="3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE">3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE</a></div><div style="clear:both;"></div>

It's helpful to Use "online Regex tester" for visual debug regular expression

1 Comment

This removes class="document" and the text 3.2.1.&nbsp;&nbsp;&nbsp;&nbsp;EXAMPLE. Have you tried it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.