1

Could someone give me the magic answer to my 87 year old dad's problem? For years, at least for 10 years he used the following simple javascript code to open a new window from a homepage like this:

<a href="javascript:openWin12('videok.html')">

but finally I've managed to convince him to stop using this code because it messes up Xenu search results, and I am sick and tired of the new windows popping up while browsing his website. So, I suggested him to use this code to open a new tab or page instead of new window from now like this:

<a target="_blank" class="y" href="videok.html">

He ended up liking this new code so much that he wants to replace all the javascript codes on his website to this one (several hundred if not thousand) lines in hundreds of pages, so that now I'm trying to find a way to do this for him in Notepad++ or MB-Search&Replace.

So, the task is the following:

The script looks like this in theory:

<a href="javascript:openWin12('videok.html')">

code1 wildcardtext code2 code3

where code1= <a href="javascript:openWin12('

widcardtext = videok.html code2 = ') code3 = ">

where code1 should be replaced with

<a target="_blank" class="y" href="

wildcardtext should be left alone,

and code2 should be deleted

code3 should be left alone

by the way, here is his webpage, to prove that my story is real: www.lezo.hu

1

You should be able to use a regular expression in notepad++ to do this.

Find:

<a href="javascript:openWin12\('([^)]+)'\)">

Replace with:

<a target="_blank" class="y" href="\1">

If you use the "Find in Files" you can select to do this to an entire directory tree.

enter image description here

How does this work:

If you are not familiar with regular expressions, they a small programming language used to in finding (and replacing) text. The magic in this one is here:

\('([^)]+)'\)

This says,

  1. \( says find a (, the \ is needed because ( is special.
  2. then ( says start a capture group. This used for the replace.
  3. [^)]+ says find one or more of anything but a )
  4. ) ends the capture group
  5. \) matches a )

Then in the replace the \1 says to take the text from the capture group and put into the text of the replace.

| improve this answer | |
  • Hi Stephen, Thanks a bunch for your quick reply, your solution took a huge "mental" burden off my shoulders. :) – Geza Apr 23 '17 at 20:16
  • It is so simple but elegant at the same time. It took me ten minutes to comprehend it fully. Before I posted this question here I did a Google search on regular expression in the hope finding a really good website where I can learn it, but I couldn't found any. By any chance, can you point me to one, or I should just start watching tutoring videos like these: tinyurl.com/k36xmrh ? I don't wish to reach the Phd level in regex, just do simple searches in html files. – Geza Apr 23 '17 at 20:25
  • I generally use this one: regular-expressions.info/examples.html for explaining complicated concepts, but it may be a bit advanced, I don't know. I also usually test them in the actual application, but regex101.com can be used to play around with them. – Stephen Rauch Apr 23 '17 at 20:57
  • Mostly regex's just take practice. Lots of it. Which may not be practical for people who don't use them often. – Stephen Rauch Apr 23 '17 at 21:03
  • 1
    Your explanation omits mention of the quotes, suggesting you added them after the fact. If so, you possibly overlooked a related change: using a quote rather than closing parenthesis for the negated character range. – Ben Voigt Apr 24 '17 at 2:28
0

You could give find and replace a try. It has a simple user interface. I often use it to search for UNC paths in scripts that have changed and need to be edited - The perfect tool for people (like me) who are always having a hard time with RegExps ;)

| improve this answer | |
  • Thanks for your software suggestion, I'll give it a try. – Geza Apr 24 '17 at 14:43

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.