Turning Bold into Strong with Regex & NotePad++

I’ve been hand coding a site and I was a little lazy. Instead in using the strong tag to make text look bold I used the bold tag.

Ok, that might not be a big deal to you but to some HTML fanatics the difference between <b>Hi There</b> and <strong>Hi There</strong> is ground for excommunication from the cool kids club. Being lazing I figured the difference was not important enough to warrant me typing an extra 10 characters for each tag. But in the middle of the project I saw the light. (Modern browsers, text readers, and future things we have not invented yet will “do the right thing” with strong tags. Bold tags are just fossilized formatting.)

So now I had a bigger problem: How do I turn all those <b>’s and </b>’s into <strong>’s and </strong>’s? Of course regular expressions would work–if I could figure out the syntax. I mean, it’s been a long time and I always found regex to be the classical Latin of the programming world. Boring but important 🙂

To complicate things I am using NotePad++ to edit my hand hold HTML. NotePad++ is a great editor (and it’s free) but often does things it’s own way. It’s the Frank Sinatra of Window’s text editors.

To refresh my memory of regex syntax I found a great site, RegExr, that let’s you experiment with regular expressions until you beat them into submission. It’s written in Flex 3 and is a fine example of both a programmer’s tool and an Adobe rich media application.

After a bit of fooling around I discovered the pattern to capture a string inside a bold tag…

and to replacement was

This magic would not work if the bold tags had any attributes but I would have used an actual CSS style if I needed any more complexity than bold text.

Anyway this didn’t quite work with NotePad++. A little more digging (via Google and Stack Overflow not the NotePad++ help system) and I discovered that NotePad++ doesn’t need the regex switches and uses / instead of $ for captures. The working search and replace strings are…

Yey! Now I can continue to be lazy and fix it later!