The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. November 21, 2008, 03:28:00 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Tutor needed!!  (Read 746 times)
m0nkeymafia
Expert
****
Offline Offline

Posts: 236


Check it!


View Profile
« on: May 28, 2007, 01:09:53 PM »

Hey

I class myself as being "ok" with regex, i can pretty much scrape or steal a pattern that will jsut about work for me.
I usually end up with something that is "almost" right and then I hack something in to get the actual content I want.

Is there anyone skilled enough to perhaps give a short walk through on how to tailor a regex for how you want it?
Also, perhaps, to illuminate the difference between perl and php regex notation type etc

\o/
Logged

I am Tyler Durden
thedarkness
Global Moderator
Lifer
*****
Offline Offline

Posts: 580



View Profile
« Reply #1 on: May 28, 2007, 06:32:21 PM »

Hey Monk,

I can certainly help you on a per case basis, but I'm too busy at the moment (ask anybody) to do any sort of in depth analysis of regex's in general.

PM me if you need to.

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
perkiset
Olde World Hacker
Administrator
Lifer
*****
Online Online

Posts: 5142


:sniffle: Humor was so much easier before.


View Profile
« Reply #2 on: May 28, 2007, 07:57:11 PM »

I can help as well - they're not as tough as you think. But my strongest recommendation is the book "Regular Expressions, the Complete Tutorial" by Jan Goyvaerts. His site is here:

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

and is excellent - you can get the book quickly through amazon here:

http://www.amazon.com/exec/obidos/ASIN/1411677609/jgsbookselection

It is a quick read and worth every penny. I keep it beside my desk to this day because it's so great and handy.

/p
Logged

If I can't be Mr. Root then I don't want to play.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3384


View Profile
« Reply #3 on: May 29, 2007, 02:20:46 PM »

actually we might be able to build a general guideline type thread.

So here's my 

regex itself is not hard. its just a replacement language. simply put, you are using codes to represent longer strings. like a hash.

so in essence you are trying to find patterns within sets of strings.

the way i deal with it is probably similar to most. I first determine what i am intending to do. find a pattern to mark the beginning of a string i want to capture? replacement? validation?

then i analyze the data i have to work with. for example, if its phone numbers from a database, which i want to validate I look at random samplings of the data.
I might see
8781239870
(444)1279790
(024) 123 1234
123.123.1422
123-123-1234
etc
etc

one of the biggest difficulties with regex is seeing all possibilities of a pattern or result. creating the regex pattern is usually then just a matter of replacing the elements of the patter that are the same within all datasets, or at least non-exclusive of a valid result.

for example an american phone number should never have a letter in it, except after at least the 7th character
1231234x204 no area code, with an extension.

the codes quite frankly are a very short list, and not worth worrying about memorizing, since you will just through use. But the challenge is in making the mental switch to pattern recognition.

the best way to learn it though is by doing, as usual.
Logged
Bompa
Administrator
Expert
*****
Offline Offline

Posts: 208


View Profile WWW
« Reply #4 on: June 27, 2007, 02:24:15 AM »

Hey

I class myself as being "ok" with regex, i can pretty much scrape or steal a pattern that will jsut about work for me.
I usually end up with something that is "almost" right and then I hack something in to get the actual content I want.

Is there anyone skilled enough to perhaps give a short walk through on how to tailor a regex for how you want it?
Also, perhaps, to illuminate the difference between perl and php regex notation type etc

\o/

I always wanted to be a tailor.

1. Write the new regex in a new script dedicated to just that regex.
2. Write the regex so that it catches ALL of the designated text.
3. Put in some sort of 'match' so that the regex skips over part of the beginning of the text.
4. Put in another 'match' so that the regex stops matching before the end of the text.
5. Keep changing those two 'matches' and note how the result diminishes until you have ONLY that
which you originally want.

Cheesy


Bompa








Logged

Bompa
Administrator
Expert
*****
Offline Offline

Posts: 208


View Profile WWW
« Reply #5 on: June 27, 2007, 02:32:43 AM »

Also, perhaps, to illuminate the difference between perl and php regex notation type etc

There are no significant differences in the syntax of the regex, itself, but of course, the regex will be
surrounded by code that is different.

PHP uses:  PCRE with means Perl Compatible Regular Expressions  http://www.php.net/pcre


From:  http://www.pcre.org/pcre.txt
"The PCRE  library is a set of functions that implement regular expression pattern matching
using the same syntax and semantics as Perl, with just a few differences."


My bet is that you will never run accross one of those differences.


Bompa

Logged

m0nkeymafia
Expert
****
Offline Offline

Posts: 236


Check it!


View Profile
« Reply #6 on: June 28, 2007, 09:28:41 AM »

Yanno a combination of two things have helped me greatly in this area.

Firstly a need to do it, nothing like needing to do something to make you learn
Secondly I got this program called editpad pro, u can get a free trial, you can load up some text [in my case html / css] then search on it using regular expressions.

So you can tweak your regex until you get what you want, real time, saving you altering your php, uploading it, refreshing the page and figuring out what went on Smiley
Logged

I am Tyler Durden
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!