2 Replies - 8893 Views - Last Post: 17 January 2012 - 10:25 AM Rate Topic: -----

#1 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,462
  • Joined: 12-June 08

[link] Regular Expression Primer

Posted 17 January 2012 - 10:00 AM

http://www.switchont...pression-primer

Man.. who doesn't have problems with regular expressions. I forget half of what I know and have to relearn it each time. *sigh*

Quote

Pattern recognition is a very hard thing to get right, and as a developer it can be as easy as a few lines of code or more than you can count with fingers and toes. Today we are going to go over a very common tool used for text pattern recognition: regular expression. So let's get started and dive right i


Is This A Good Question/Topic? 0
  • +

Replies To: [link] Regular Expression Primer

#2 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Re: [link] Regular Expression Primer

Posted 17 January 2012 - 10:14 AM

Is learning regular expressions really worth it? It sounds like what they can do could be done in about 5 lines.

/* Detecting a-z, A-Z, 0-9 in string */

// with regular expressions
if(preg_match("/^[a-zA-Z0-9]+$/", $str) == 1) {
    // string only contain the a to z , A to Z, 0 to 9
}

// Done without regular expressions
if(ctype_alnum($str)){
    // string only contain the a to z , A to Z, 0 to 9
}



Other things like email and IP addresses can be checked by using filter functions.


Also, is your link broken? It's taken me to a page listen a whole bunch of tutorials.

This post has been edited by creativecoding: 17 January 2012 - 10:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,462
  • Joined: 12-June 08

Re: [link] Regular Expression Primer

Posted 17 January 2012 - 10:25 AM

Yes.. I would think learning regular expressions is worth it. Most recently I've been using it break apart emails to snag specific information and cram that into a database... if you've ever looked at the code behind in an email you'll know it's a nightmare. so I set up expressions that snag specific chunks of text from matches (because there might be the word "from" about four times in the damn header). A pain in the but to set up and get right, but oh so awesome when it kicks in.

In both of your examples I think you are taking a more cudgel approach to regex. I mean sure you can use it to see if is alphanumeric, but what about when you want to find one specific word that follows a commonly used word but also has a specific ending sequence? *shrug* I find bending a rule to fit that perfect is worth the effort.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1