Thread: Tutor needed!!
m0nkeymafia

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/

thedarkness

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

perkiset

I can help as well - they're not as tough as you think. But my strongest recommendation is the book "

Regular Expression

 s, the Complete

Tutor

 ial" 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

nutballs

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

So here's my  Applause

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.

Bompa

quote author=m0nkeymafia link=topic=273.msg1812#msg1812 date=1180382993

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.

Applause


Bompa








Bompa

quote author=m0nkeymafia link=topic=273.msg1812#msg1812 date=1180382993

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 Expression

 s  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

m0nkeymafia

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 expression

 s.

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 Applause


Perkiset's Place Home   Politics @ Perkiset's