So you wanna learn Regex? - Part 3

Welcome to So You Wanna Learn Regex? Part 3.

In our last exercise, we looked at a simple way to wrap a function argument inside a new function. This was accomplished by making a pattern, defining a group and using a back reference. This time we will look at how to clean some strings.

Say for example, that you run a website called The Health Challenge and say for example, you wanted to use some of your fine tax dollar funded research to deliver motivating messages to the members.

Well, you could just happen across Small Steps and just use their content. After all, it is in the public domain. So you happily cut a LARGE chunk of these from the web site, but now you have to clean them.

Assume this set of declarations:

(# 11)  	Avoid food portions larger than your fist.
(# 12) 	Mow lawn with push mower.
(# 13) 	Increase the fiber in your diet.
(# 17) 	Join an exercise group.
(# 20) 	Do yard work.
(# 24) 	Skip seconds.
(# 25) 	Work around the house.
(# 26) 	Skip buffets.
(# 29) 	Take dog to the park.
(# 30) 	Ask your doctor about taking a multi-vitamin.
....( 700 more lines)

What we want, is to turn: (# 11) Avoid food portions larger than your fist. into: Avoid food portions larger than your fist. See, we like the content, we don't like the parentheticals nor the whitespace. Do we flex our forearms in preparation for a copy/paste session? Do we call KeyboardsAreUs.com and have 2 fresh keyboards airdropped, knowing we'll wear out some keys? (if you said yes, please delete your hard drive and apply at KFC.) Regular expressions are our friends. A Regex is a pattern matcher, and it can do stuff. We can see our code is repetitive and the pattern we want is: Get rid of the parentheticals and the extra whitespace. (Same stuff we'd do over and over via cut/paste/etc, isn't it? Though in a copy paste, you are talking about 5 keystrokes per line times 700 lines. That is 3500 keystrokes, unless you type like me, in which case it would be nearly 4 million.)

So as you know, we define this pattern in the gobbledegook of regular expressions. When read one chunk at a time, these actually make sense. We'll go through the exercise, then look at why it worked.

In Eclipse, perform the following:

[More]

So you wanna learn Regex? - Part 2

Welcome to So You Wanna Learn Regex? Part 2. In our last exercise, we looked at a simple way to add a new attribute to an HTML tag. This was accomplished by making a pattern, defining a group and using a back reference. This time we will look at a slightly more complicated use case.

Assume this set of declarations:

product.setColor(arguments.color);
product.setSize(arguments.size);
product.setCondition(arguments.condition);
product.setRating(arguments.rating);
product.setReliability(arguments.reliability);
product.setNeedsBatteries(arguments.needsBatteries);

What we want, is to turn: product.setColor(arguments.color); into: product.setColor( htmlEditFormat(arguments.color) );

Normally, this would be a forearm/wrist fatiguing flail on the keyboard, furiously cutting/pasting and generally flapping about. Not so with Regular Expressions. A Regex is a pattern matcher, and it can do stuff. We can see our code is repetitive and the pattern we want is: Take Everything Inside The Parenthesis, and Wrap It In A htmlEditFormat() Function. (Same stuff we'd do over and over via cut/paste/etc, isn't it?)

We can define this pattern in the gobbledegook defining a regular expression. When read one chunk at a time, these actually make sense. We'll go through the exercise, then look at why it worked.

In Eclipse, perform the following:

[More]

So you wanna learn Regex? - Part 1

I've had a set of blog posts stewing in my brain for a while. Steve Nelson, last year, helped me out with a Regular Expression (Regex) and I made it a point to practice my Regex skills more. This series will show how to use Regular Expressions in Eclipse and we'll learn some helpful tips along the way. This series is for you if you are the kind of developer that reads Ben Nadel's blog posts containing Regular Expressions, and has no idea what the heck he is talking about. Seriously Ben, this is unintelligible to us mere mortals:

<cfset blogContent = reReplace( blogContent, "</?\w+(\s*[\w:]+\s*=\s*(""[^""]*""|'[^']*'))*\s*/?>", " ", "all" ) />
(It looks like a catnip crazed kitty went for a prance on a keyboard, doesn't it?) Enough guffaws and such. On with the learning.

Editors Note:

Simply reading these blog posts aren't going to help you. Open eclipse, and copy/paste this stuff into your find/replace dialog. You'll learn more, or your money back!

So, firstly we need a use case. Let's pretend we are going through some old code and looking to add HTMLEditFormat around some arguments so that the forms won't break if there are quotes.

Assume this set of declarations:

<input name="fred" value="willy" />
<input name="bill" value="mickey" />
<input name="erin" value="harry" />
<input name="baz" value="pissette" />

What we want, is to turn: <input name="fred" value="willy" /> into: <input name="fred" id="fred" value="willy" /> Normally, this would be a forearm/wrist fatiguing flail on the keyboard, furiously cutting/pasting and generally flapping about. Not so with Regular Expressions. A Regex is a pattern matcher, and it can do stuff. We can see our code is repetitive and the pattern we want is: make a new attribute called 'id' and populate it with the value from the attribute 'name'... which is what we'd do over and over via cut/paste/etc. We can define this pattern in the gobbledegook defining a regular expression, of course, else I'd be writing this post about Cute LOLCats, not Cute Regexes., wouldn't I? We'll go through the exercise, then look at why it worked.

In Eclipse, perform the following:

[More]

Adobe Max Sessions Filling Up Fast!

I registered for Adobe Max a few weeks ago but never actually put my session schedule together. I'm not the biggest fan of the way Max handles it's sessions. Most of the conferences I go to do not have badge nazi's at the door banning anyone without prior registration, Max does. While I can understand logistical circumstances, I still don't like it. So, after a reminder from the blogosphere I logged in today to schedule my sessions.

Max, for me, is all about the hands-on stuff. I don't mind paying the price especially knowing I'm going to get hands-on training. Matter of fact, I sell professional training and when compared with my bill rates Max is a bargain :) !

So, if you haven't registered for Max, hurry up. If you've registered and not scheduled your sessions, you REALLY need to hurry up. I'm attaching my Max schedule to this article in case you want to see where I'm spending my time.

See you @ Max!

DW

Download Download

Win a ColdFusion Dude Camera

Registration for the CFinNC conference is filling up fast. Even though we are a free conference, space is limited so get your registrations in very soon!

The illustrious Simon Free is running a promotional conference to help not only CFinNC, but bFlex/bFusion and RIA Unleashed. You could win a limited edition, one of a kind, never to be seen again, amazingly creative, yet awesomely useful custom CF Dude Flip video camera by simply registering and Submit, in 100 words or less, why you love ColdFusion or why you are excited to learn ColdFusion!

Win a CF Dude Camera - 3 great conferences, 3 Chances to Win

Why You Should Register for CFinNC before Sept 4th

As you know, we are hard at work planning the CFinNC.com conference. CFinNC is 2 days of jam packed training and sessions on the Adobe platform (CF, Flash, Flex and AIR) and other web development topics. In this time of evaporating training budgets and non-existent funds for conferences, our free conference is the most compelling way to get trained and fired up.

We've opened registration yesterday and are pleased with the results of the last 24 hours. A big goal of the conference is to reach and strengthen existing users of the Adobe platform by offering all levels of content. We have another goal, which is to reach and impress students and developers of alternate platforms on the power and potency of the Adobe platform.

So to reach the first goal, we've opened registration and are initially promoting through the usual Adobe-centric information channels to reach the existing user base. We want to serve the needs of the Adobe platform users as this was our original driving force to start this conference.

To reach the second goal, we'll begin heavy promotion through user group channels, social channels and through a registration drive partnership with DZone.com. This second wave will likely push us to capacity and give us a large attendee base that will be getting their first exposure to the Adobe platforms.

So, if you are interested in coming, and happen to read this post, please decide and register soon. The floodgates open somewhere around September 4th.

-DW

Free ColdFusion, Flex AIR Conference in North Carolina

The organizers of the CFinNC 2009 Conference are proud to announce the ColdFusion in North Carolina 2009 Conference to be held October 17-18, 2009 on the Centennial Campus of NC State University in Raleigh, North Carolina. The conference will be aimed at ColdFusion and Flex developers and others who are interested in web design using these technologies.

Registration for the event will be FREE which includes entry to the weekend event and all presentations.

In preparation for this conference, we would like to hear feedback from you and your members on what types of content you would be interested in hearing. We hope to make this conference relative to all levels of developers, so your input will be invaluable.

Please visit our website www.cfinnc.com for more information. We are currently accepting submissions for presentations. If you have a topic you would like to speak on, please go to www.cfinnc.com/page.cfm/presenters for more information.

Please announce this to your members. We are really excited at the opportunity to organize this conference and hope that it will be a useful resource for you and your members.

Sincerely,

The CFinNC 2009 team

NC Conference - New Date Proposed

Planning for the NC ColdFusion conference is in high gear. We got excellent feedback on the conference dates/details from both speakers and from attendees. Most importantly, we realized our proposed date accidentally collided with the BFusion/BFlex conference. The Bfusion/BFlex conference is our inspiration for the NC conference. Bob Flynn, conference organizer, and others, have been very supportive of the NC Conference and we want to show our respect by not scheduling on the same day as them. Thus, after much discussion, consultation of calendars and the like, the new proposed schedule is Oct. 17-18th.

If we can make Oct. 17-18th work for the community, then we'll move ahead with that. Our next chance would be to do something in the Spring. (Or raise the price and do it in the Bahamas in winter :) )

The other option on the table is whether to provide a second day of training on the Adobe Flex framework. We propose a 6 hour Bring Your Own Laptop session targeted at beginner level Hands On Flex training. If you have some programming experience and want a hand making your first (or second) Flex application, this is for you. We're looking for responses from the community of whether or not this is interesting.

So if you are considering attending/speaking, please let us know how you feel on the following:

  • Does Oct. 17th - 18th work for your schedule?
  • Are you interested in attending/speaking/teacher assisting the Oct. 18th 6 hour Bring Your Own Laptop session targeted at beginner level Hands On Flex training?
  • Are you interested in more ColdFusion sessions on Oct 18th instead of Flex training?

Thanks for sharing your opinions and helping us tune this conference for the good of the community.

Need Feedback on Proposed Date for NC ColdFusion Conference

North Carolina Conference?

Hi Folks, we've been working pretty hard to line up a good ColdFusion conference for North Carolina and the surrounding areas. The original idea was to have a 1 day conference with 6 sessions and a lunch. All this for 50$.

Tell me more...

Thanks to some generous sponsors, we may even be able to drop the price a little, offer a conference T-Shirt and let the State employees attend for free, since they work so hard to keep this state going.

Where/When would the conference be held?

We propose to hold the conference in Raleigh, North Carolina on Oct 24th. We'd like to get an idea of the number of attendees and the number of interested speakers for this date/location combination.

If you are interested, please leave a comment below and let us know whether you are interested in any of the following:

  • State Employee
  • Attendee
  • Speaker

Thanks for reading and thanks to all the people who have helped us get this far in planning. We appreciate the support!

ColdFusion Is The Most Elegant Expression Of Business Solutions

I was emailing back and forth with a very smart group of people this morning and had a thought that seemed worth repeating. ColdFusion is the most elegant language to express business solutions.

Need charts for your dashboard? No problem.

Want to export a report to PDF? No problem.

Want to intake data via PDF forms and generate Presentations with the data? No problem.

Want to write a Flex application that adds meetings to Microsoft Exchange servers? No problem.

The list goes on and on and on and on and on.

ColdFusion is often lumped in with PHP and other general web scripting languages, and it can certainly fit there. However, the ColdFusion team over the years has worked very hard to put useful, relevant functionality for business applications. As a result, ColdFusion is the most elegant expression of business solutions on the market today!