WARNING: This post contains geeky coding fun with a very mild regular expression. Read and try to understand at your own risk.

Fun project today, I had to substitute each & with its HTML equivalent (&) but not any ampersands where the substitution had already taken place. Basically where data entry had been sloppy and included both HTML formatted code and non-formatted code.

For example B&W should become B&W but B&W should not become B&W.

Using http://regexpal.com to check my work I came up with the following regular expression:

Interpreted: Match & (except when immediately followed by (one or more letters (A-Z upper or lower)) OR (a # followed by 1 or more digits) AND a ; )

My Test Case:

I also found a handy Regular Expressions Cheat Sheet by DaveChild at cheatography.com

About Chad Leigh Kluck

I enjoy technology development and management by following new trends, change and disruption, and security. I have a Master of Science in Software Engineering and my hobbies include railroads, history, do-it-yourself projects, writing, and ham radio (K0RRX). More...

I enjoy comments and feedback. Let me know if you have anything to share with me like stories, pictures, or other media. You can also contact me directly via the contact form. I'd love to hear from you!

Leave comments or feedback