I use regular expressions just often enough to have to totally re-learn them every time I need to use them. After a round of Google searches, reading over a few good regex sites (here’s one) and a bit of head scratching and code tinkering I end up with the code I need.
In this particular case I needed append a variable with punctuation in cases where the variable ended in an alphanumeric character. Regex to the rescue!
1
2
3
4
5
6
7
<cfset variables.question ="what does the yellow light mean"/><cfifReFindNoCase("[a-zA-Z0-9]$", variables.question )><cfset variables.question = variables.question &"?"/></cfif><cfoutput>
#variables.question #
</cfoutput>
Reverend Jim Ignatowski
This has nothing to do with regular expressions, but it’s a classic moment from Taxi.
You
The next time you need some regex help you may want to check out http://www.regular-expressions.info. If you have any good regex tips or sites leave them in the comments below. As usual, spammers will be shot on site.
I’m into my first week at my new job and I’ve been spending some time getting my workstation setup. This task includes getting Firefox installed and adding some key Add-Ons. Here’s my list…
It’s hard to believe, but this year’s CFUnited will be the last. I had a chance to attend CFUnited a few years ago and found it to be fun and inspiring.
I urge my fellow ColdFusion developers to take advantage of CFUnited this year (while it’s..sniff…still here). As always the speaker and topic lineup is top notch.
I’ve read and coded my way through the first chapter of Head First Design Patterns and enjoyed working with the MiniDuckSimulator sample. The author(s) make a good case for favoring composition over inheritance. I look forward to understanding this concept on a deeper, actionable level as I continue onto Chapter 2. I’ve included some (but not all) of my code from Chapter 1…
/*
MiniDuckSimulator.java
creates a new instance of MallardDuck and ModelDuck
and demonstrates the different behaviors of each
*/publicclass MiniDuckSimulator{publicstaticvoid main(String[] args){System.out.println("-- new MallardDuck instance...");
Duck mallard =new MallardDuck();
mallard.performQuack();
mallard.performFly();System.out.println("-- new ModelDuck instance...");
Duck model =new ModelDuck();
model.performFly();// now he can fly!
model.setFlyBehavior(new FlyRocketPowered());
model.performFly();}}
1
2
3
4
5
6
7
8
9
10
11
12
/*
MallardDuck.java
a duck that has wings and can quack
*/publicclass MallardDuck extends Duck{// constructorpublic MallardDuck(){
quackBehavior =new Quack();
flyBehavior =new FlyWithWings();}}
1
2
3
4
5
6
7
8
9
10
11
12
/*
ModelDuck.java
a duck that cannot fly
*/publicclass ModelDuck extends Duck{// constructorpublic ModelDuck(){
flyBehavior =new FlyNoWay();
quackBehavior =new Quack();}}
1
2
3
4
5
6
7
/*
FlyBehavior.java
the interface!
*/publicinterface FlyBehavior {publicvoid fly();}
Over the last few days I’ve been sinking my teeth into Head First Design Patterns. I’m really enjoying both learning about Design Patterns as well as slinging some Java code.