Jump to content

[SOLVED] Regular Expression Studying


shane18

Recommended Posts

When I was in my 1st block of school today, I had my work done so I was trying to fully understand how the regex engine works. I written out some regex patterns and thought about what it might come out too.

 

---- ---- ----

 

Example 1:

 

.Shane Hacked into the Command Console!

/(\.|!)(.+)\s?(.+)?/

1> .

2> Shane Hacked into the Command Console

3> !

 

---- ---- ----

 

Example 2:

 

.Shane Hacked into the Command Console!

/(\.|!)(.+?)\s(.+)/

1> .

2> Shane

3> Hacked into Command Console!

 

---- ---- ----

 

Example 3:

 

.Shane

/(\.|!)(.+?)\s?(.*)/

1> .

2> S

3> hane

 

---- ---- ----

 

Example 4:

 

.Shane Test blah blaaa

/(\.|!)(.+?)(?\s.+))/

1> .

2> Shane

3> Test blah blaaa

 

---- ---- ----

 

>Questions

1-Was my guessed out come for each example correct? If not, why so?

2-Why does each example*EXCEPT FOR EXAMPLE 4* process to that outcome? Detail explainations please!

3-Does the regex engine scan the whole pattern before trying to match it?

  -Look at example 3, I can't understand if it knows the lazy is followed by a greedy before it starts matching and thats why it only gets the S, or is it because it scans the whole pattern first and knows theres a greedy afterwards?

4. Any other important notes about lazy, greedy, backtracking, or anything of this nature, please include this information in your post!

 

(I know that this is a lot to ask, but please help me become a better regular expression programmer. This is the only part I'm stuck on.)

Link to comment
Share on other sites

(I know that this is a lot to ask, but please help me become a better regular expression programmer. This is the only part I'm stuck on.)

 

Yep, this is like your 3rd or 4th consecutive post on getting help (not that asking for help is a bad thing). But I really think that your best bet would be to go in detail over the tutorial links I provided in one of your other posts.. and I still think you would benefit immensely from getting this book.

 

Don't get me wrong. Again, nothing wrong with asking for help (glad to see you are enthusiastic about learning regex).. but if it's going to boil down to just constantly posting and asking for explanations instead of reading tutorials and books on the subject, you're dragging the learning experience out unnecessarily. While doing your own research is not the easiest way, it is the best way IMO. There are plenty of resources out there to learn off of. Once you gain more knowledge through well written tutorials and books, you'll find that you don't have to ask as many questions, as you will have learned a lot during your self educational process.

 

Self initiative goes a long way in life.

"Give a man a fish, he can eat for a day.. teach a man to fish, he can eat for a lifetime."

Link to comment
Share on other sites

I read a lot of tutorials, they never go into detail with the engine, but w/e i won't come here anymore.

 

If you really want to learn, invest in the book in the link.  It goes into more detail than you will ever care to know, and then some.  It goes into very gritty detail about how the regex engine matches things, backtracks, etc.. blahblah trust me, just get the book.

Link to comment
Share on other sites

I read a lot of tutorials, they never go into detail with the engine, but w/e i won't come here anymore.

 

Shane, you misunderstand me.. I'm not saying don't come here anymore (again, nothing wrong with asking for help).. I'm trying to illustrate that taking some self initiative goes a long way (and that book by the way explains the mechanics of how regex engines *think*) and that's why I recommend it. I think you would learn a lot from it.  :)

 

This forum is certainly not about turning members away. We want to foster this place as a source of learning and participation, not the other way around.

So by all means, do drop by and ask questions. All I'm suggesting is to do some research as well. You have been pointing to resources to help you achieve a better understanding of regex.

 

Hopefully you understand where I'm coming from a little better.

Link to comment
Share on other sites

sorry for the over reaction.. its just i been programming since i was 9 and im 18.. and i just now needed regex for some things on a HUGE project.. and i never hit a fork in the road before... and i can't stand being stuck

 

The reason I got started on regex, other then e-mail validation.... is cuz to save tons of pages and code i wanted to make a Command Console.. where i enter a symbol.. then if REQUIRED username and then if required reason/extra values seperated by a comma.... and it would go to a switch on a page and excute it.. instead of 10 pages of forms and code lol.. i liek to make entire sites onto one page... atm i got one project a entire site on  1 page... 1400 lines and about 70% complete...

 

btw the command console thing i thought about is like

 

.shane he said some bad things= bans shane for he said some bad things

!shane he is hackin= suspends shane for 24 hours for he is hackin

_ = list logs

~ = list reports

.maintenance START,END,Reason = inserts a maintenance notice and start/end time

 

its awesome.. im into 1 line command things

Link to comment
Share on other sites

"entire site in one page" is not really idea for real world application, though.  There's a reason why MVC exists.  When it is just you that is touching virtually everything, hey whatever gets you off, but in the real world, you have many people all working on the site for various reasons.  Like for instance, any given client could have a team responsible for nothing but database, another team for nothing but actual server-side coding.  Another team responsible for content/creative.  Another team responsible for doing things like adding tracking code to things as ad-hoc report requirements come up, etc.. and the point is, when you have tons of people all needing to work on the site, you do not want them to all be accessing the full enchilada, because 99% of the time, the tracking people won't know jack shit about server-side coding.  The content people won't know jack shit about ANY coding, etc... and on top of that, many of these teams are broken down into sub-teams, and many of them are not actual employees of the client, but whole other 3rd parties.  So you DON'T want to be having to give 100% access to everything to everybody.

 

Link to comment
Share on other sites

I started the site, and I'm the only one who works on it... its like 2 weeks from completion... then which i have like 30 people that wanna be able to sign up on it asap... plus more later i hope... after all its just a hobby :)

 

I got a computer bud of mine testing every part and button of my site after every addition.. so life is all good

 

Been working on it for about 1-2 hours a day for 6 months...... a lot of organization and code...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.