Alex Rivera | Logout

What have you used Regular Expressions for?

Asked 2009-01-01T02:39:17.060
10

I have heard of regular expressions and only seen use cases for a few things so I don't think of using them very often. In the past I have done a couple of things and it has taken me hours to do. Later I talk to someone and they say "here is how to do it using a regular expression".

So what are things for which you have used Regular Expressions? If I get more examples then maybe I can begin to know when to look for and use them.

Edit
Report

2 Answers

11

The last thing i used a regular expression for was to validate text input to make sure the input string conformed to certain rules, for example the second character had to be a '-'.

I read your question and immediately thought of this.

alt text

EDIT: Forgot to mention this an XKCD comic. http://xkcd.com/208/

answered 2009-01-01T03:46:28.233
0

In ASP.NET if you use user controls or master pages, even if you name your controls uniquely, they get mangled by the framework. I wrote a little wrapper around the prototype $ function to allow me to get mangled controls in javascript despite the name mangling. It uses a regular expression to search the DOM for controls that end with the appropriate name.

I also use it heavily in client/server-side validation of inputs that need to match specific input patterns.

answered 2009-01-01T02:52:29.747

Your Answer