
![]() |
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 regexfor how you want it?Also, perhaps, to illuminate the difference between perlandphpregexnotation type etco/ 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 Expressions, the CompleteTutorial" 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 ![]() regexitself 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 regexis seeing all possibilities of a pattern or result. creating theregexpattern 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 learnit 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 regexfor how you want it?Also, perhaps, to illuminate the difference between perlandphpregexnotation type etco/ I always wanted to be a tailor. 1. Write the new regexin a new script dedicated to just thatregex.2. Write the regexso that it catches ALL of the designated text.3. Put in some sort of 'match' so that the regexskips over part of the beginning of the text.4. Put in another 'match' so that the regexstops 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. ![]() Bompa Bompa
quote author=m0nkeymafia link=topic=273.msg1812#msg1812 date=1180382993 Also, perhaps, to illuminate the difference between perlandphpregexnotation type etcThere are no significant differences in the syntax of the regex, itself, but of course, theregexwill besurrounded by code that is different. PHPuses: PCRE with meansPerlCompatibleRegular Expressions http://www.php.net/pcreFrom: http://www.pcre.org/pcre.txt "The PCRE library is a set of functions that implement regular expressionpattern matchingusing 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 learnSecondly 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 regexuntil you get what you want, real time, saving you altering yourphp, uploading it, refreshing the page and figuring out what went on![]() |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads