I had been looking on the Internet for a solution to a program I had be working on and sadly didn’t come up with one. I was trying to find a way to use regular expressions to find all the html anchor tags in a string along with matching a wild card URL (ie: secnem.com.*test.html). And after many hours of thrusting my head into my keyboard I came up with:

/<a [^><]*href=[\”\’][^\”\’><]*<rule>[^\”\’><]*[\”\’][^>]*>\s*.*\s*<\/a>/iU

You’d replace <rule> with what ever url rule you want, except for any wild cards in the url I needed to use [^\”\’><]* instead of just .* . This would prevent it from matching outside of the anchor. Bascially [^\”\’><]*  means: match any character except a double quote, single quote, greater than sign, or less than sign. All of which should not be in the href field to begin with.

If you wanted to see what the content of the anchor tag was or the matched href, simply put some brackets around like so:

/<a [^><]*href=[\”\’]([^\”\’><]*<rule>[^\”\’><]*)[\”\’][^>]*>(\s*.*\s*)<\/a>/iU

Hope this helps someone. You can of course adapt this to other html tags by replacing ‘a’ for ‘table’ or w/e. Same with the href. larsolavtorvik.com has a great resource for testing regex in real time and addedbytes.com has a great cheat sheet as well.

Previous ArticleNext Article
B.

Bulk Add IP Addresses

I do a lot of local development with Internet Information Services and either ColdFusion, PHP or ASP.net and for the longest time I would actually run the websites on separate ports on 127.0.0.1.

Unfortunately running multiple websites on various other ports causes some issues like:

  • Port conflicts with other programs
  • Remembering which port is used for what website
  • Causes problems with some websites that look for port 80
  • Doesn’t really work with SSL (port 443)

So what I started doing was running my websites on separate private IP addresses which are local to my machine only, and this worked GREAT! I could load up websitexyz, bind it to IP 1.1.1.10, setup SSL to work on port 443 for 1.1.1.10 and I would go about my business.

The only downside was when I would run out of IP addresses, because I would only add about 5 to 10 IPs at a time to my local loopback adapter. It is a bit of a pain in the butt to add a bunch of IP addresses in Windows, so it would take me a bit of time to do this everytime I needed more IPs.

That was until I ran into a small batch script which can add as many IP addresses as I want in a range.

Here’s the code:

FOR /L %A IN (41,1,100) DO netsh interface ipv4 add address “ColdFusion-IIS” 1.1.1.%A 255.255.255.0

Simply copy that into either a command prompt or a .bat file and run it to add as many IP addresses in a range that you want.

Here’s the break down of the script:

FOR /L %A IN (START,INCREMENT,END) DO netsh interface ipv4 add address “INTERFACE_NAME” IPMASK SUBNET

If we take a look at my script above we see that

  • START = 41
  • INCREMENT = 1
  • END = 100
  • INTERFACE_NAME = ColdFusion-IIS
  • IPMASK = 1.1.1.%A
  • SUBNET = 255.255.255.0

What this basically equates to is adding 1.1.1.41 to 1.1.1.100 to my network adapter called ColdFusion-IIS.
It is a super handy script and saved me a bunch of time, I would recommend it 10/10 for local development.
6.

60Hz

Oh yes, 60Hz, my favorite vertical refresh rate, but why I wonder?

Well for starters it’s the best and easiest way to get a headache. I have a 52 inch Sharp LCD TV (LC52D64U) and it’s max refresh rate at 1920×1080 is 60Hz, which makes it fantastic to watch while playing anything high definition. Since I use it as a monitor, and the only way it looks decent is at 1080p, I’m currently stuck at 60Hz.

So I suppose it’s time to buy another TV… or an actual monitor for the mean time.

QQ