2

a similar question was asked on the below thread and i was able to get it working partially Notepad++ find and replace within a constant string didn't wanted to create a new question as wanted to ask a small help by asking in comment but my reputation is less so have to create a new question.

I have a text file in the form where the below example is repeated numerous times

this is random text
https://helloworld.com

another random text
https://iamdoinggood.com

more random text
https://howareyou.com

the problem is to replace only the string starting with https:// to someting like

this is random text
<span"><a href="https://helloworld.com">https://helloworld.com</a></span><br />

another random text
<span"><a href="https://iamdoinggood.com">https://iamdoinggood.com</a></span><br />

more random text
<span"><a href="https://howareyou.com">https://howareyou.com</a></span><br />

I tried doing this using the find and replace with regular expression ticked , using the command

find - ([https].*)

replace - <span"><a href="\1">\1</a></span><br />

but instead of only modifying the string starting with https:// its also modifying other text and giving me result as below i.e. jumbling up of certain part of normal text and also adding additional html tags to it which is not intended

this is random text
<span"><a href="https://helloworld.com">https://helloworld.com</a></span><br />

ano<span"><a href="ther random text">ther random text</a></span><br />
<span"><a href="https://iamdoinggood.com">https://iamdoinggood.com</a></span><br />

more random <span"><a href="text">text</a></span><br />
<span"><a href="https://howareyou.com">https://howareyou.com</a></span><br />

any help on what I might be missing here

3
  • I see lots of regexp newbies try to use [https] to match the literal string https. Where do you get misunderstandings like this? – Barmar Aug 2 '20 at 19:36
  • @Barmar - I feel to misunderstand things and then understand with some guidance is how we learn.. that is where we all play our roles :-) – beastboy Aug 3 '20 at 6:43
  • I wonder if the educational material is poor, since so many people make the same mistake. Did you misunderstand this in a tutorial? – Barmar Aug 3 '20 at 14:14
5

You have a problem in your RegEx.

  • Hit Ctrl+H to open Find and Replace.
  • Set "Find What: " to (https://.*).
  • Set "Replace with: " to <span"><a href="\1">\1</a></span><br />.
  • Then Check Regular Expression in search mode group.
  • Then click Replace All.

Your problem is that [https] will match if there are h,t,p,s characters and not the whole string.

enter image description here

1
  • Thank you @Wasif_Hasan for the solution and explaining the missing part.. Have a good day ahead. – beastboy Aug 3 '20 at 6:45
2

It works with changing the Find string to (https://.*).

The syntax of [https] means "one of the letters h, t, t, p, s".

enter image description here

1
  • Thank you @harrymc.. it worked... – beastboy Aug 3 '20 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.