Regular Expressions for Strings

Today we switched over the site’s “Write Us” function to a much simpler WordPress solution. We posted an article on this in our HOME page.

The old solution linked to a cgi page. In WordPress installations, and we have a lot of them, the changeover was simple: change the coding on a button and a couple of include files, and you’re done. All pages, all buttons, in under five minutes per department.

We didn’t appreciate how many unconverted legacy HTML pages we still have, many going back to the 1990’s. DreamWeaver found 1,292 links needing change. Typically two links per page, that’s between 500 and 600 HTML pages. Except for the uploads, the powerful find/replace feature can make short work of that too.

There was a BIG problem.

OLD link:

NEW link:

Do you see the problem yet? You can do a search on the URL, but the /subject=Random%20Password string is a cgi parameter and is different for every page.

Changing 5 to 6 hundred pages manually is out of the question. We used to do it when the site was smaller, but we won’t do it now. I know about regular expressions, and have a library of canned routines I use in Perl, but I didn’t know how to use them in the DreamWeaver HTML editor, though it reportedly sports very powerful RegEx support for string searches.

To tell you the truth, I loathe RegEx. But, once you know the right expression, it’s amazing how so little symbolic code can do so much. Here is what I found after two hours of research, recorded and then handed over to you straight from my NotePad text file.

Using the expression below, Dreamweaver replaced all of the links sitewide in about 30 seconds. Enjoy!

Replace the string with blanks

find: subject=[^"]*

replaces subject=pipes

This is great!

we tried subject=(D+.) on subject=Random%20Password
but it only found 'subject=Random%2'
we want to replace with blank, but here's the original example,

The regular expression you seek is: [^"]*
so if you want to change all these:

<a class="wildcat" href="lion.html">
<a><a class="wildcat" href="tiger.html">
</a><a class="wildcat" href="leopard.html">


</a><a class="wildcat" href="bigcat.html">

you search for:

</a><a class="wildcat" href="[^"]*">

and replace with:

</a><a class="wildcat" href="bigcat.html"></a>

(make sure you tick the match case & regular expressions + seclect 'source code')

698 total views, 1 views today