ID:40295
 
Keywords: utility
Kunark has posted some valuable insights about the all-powerful Regex and its plans for humanity: http://www.byond.com/members/ Kunark?command=view_post&post=40292

But my esteemed colleague leaves out one crucial detail: what, exactly, is Regex?

A reasonable definition (taken from the third link below) is: "Regular expressions, or regexes for short, are a way to match text with patterns. They are a powerful way to find and replace strings that take a defined format. For example, regular expressions can be used to parse dates, urls and email addresses, log files, configuration files, command line switches or programming scripts."

Since the notion of "searching the Internet" is foreign to many people even in this enlightened age, I've done a minimal amount of work on BYOND developers' behalf. Here, then, are some sites with fairly gentle introductions to the concept:

http://www.digitalamit.com/article/regular_expression.phtml
http://www.codeproject.com/KB/string/re.aspx
http://www.aivosto.com/vbtips/regex.html

If it sounds interesting to you, check out this search and let the games begin!

http://www.byond.com/ members/?command=search&text=regex&type=resources


Although the entire site is one giant ad for PowerGREP, RegexBuddy, and/or EditPad Pro, I also recommend

http://www.regular-expressions.info/

for quick reference and/or tutorials.
Jtgibson wrote:
Although the entire site is one giant ad for PowerGREP, RegexBuddy, and/or EditPad Pro, I also recommend

http://www.regular-expressions.info/

for quick reference and/or tutorials.

Thanks JT! (IMHO, I don't mind ads at all as long as they aren't trying to secretly install software on my system.)
Oh man. This is insanely simple, why have I not learned this earlier? This will really improve a project of mine.
I learned most of my regex knowledge from http://www.regular-expressions.info/, but the site doesn't do very good explaining it, but frankley it's still one of the best sites dispite its poor quality.

Best way to learn it is just to fudge around with it on one of the many regex tester sites. My favorite is http://regexlib.com/RETester.aspx.

Problem is that there are so many different regex engines that some things you will be taught might not be compatible with your engine. For example, in PHP I have to work around look-behind regex limitations, but I wouldn't need to in .NET.
Oh, and by the way, here is an expression that might save some of you some pain while you're learning, and luckely it's fairly simple. I know it was a pain for me while I was learning because of how much I dealt with HTML and attributes. This is how you disclude text or a pattern from your matches:

/\b(?!mytext\b)\w+?\b/g

That would match all words except "mytext".
Kunark wrote:
Oh, and by the way, here is an expression that might save some of you some pain while you're learning, and luckely it's fairly simple. I know it was a pain for me while I was learning because of how much I dealt with HTML and attributes. This is how you disclude text or a pattern from your matches:

/\b(?!mytext\b)\w+?\b/g

That would match all words except "mytext".

Have I mentioned I love you?