title: PCRE Regex Syntax
body: <p>I guess this is more or less a two-part question, but here's the basics first: I am writing some PHP to use preg_match_all to look in a variable for strings book-ended by {}. It then iterates through each string returned, replaces the strings it found with data from a MySQL query.</p>
  
  <p>The first question is this: Any good sites out there to really learn the ins and outs of PCRE expressions? I've done a lot of searching on Google, but the best one I've been able to find so far is <a href="http://www.regular-expressions.info/" rel="nofollow">http://www.regular-expressions.info/</a>. In my opinion, the information there is not well-organized and since I'd rather not get hung up having to ask for help whenever I need to write a complex regex, please point me at a couple sites (or a couple books!) that will help me not have to bother you folks in the future.</p>
  
  <p>The second question is this: I have this regex </p>
  
  <pre><code>"/{.*(_){1}(.*(_){1}[a-z]{1}|.*)}/"
  </code></pre>
  
  <p>and I need it to catch instances such as <code>{first_name}, {last_name}, {email}</code>, etc. I have three problems with this regex.</p>
  
  <p>The first is that it sees "<code>{first_name} {last_name}</code>" as one string, when it should see it as two. I've been able to solve this by checking for the existence of the space, then exploding on the space. Messy, but it works.</p>
  
  <p>The second problem is that it includes punctuation as part of the captured string. So, if you have "<code>{first_name} {last_name}</code>,", then it returns the comma as part of the string. I've been able to partially solve this by simply using preg_replace to delete periods, commas, and semi-colons. While it works for those punctuation items, my logic is unable to handle exclamation points, question marks, and everything else.</p>
  
  <p>The third problem I have with this regex is that it is not seeing instances of {email} at all.</p>
  
  <p>Now, if you can, are willing, and have time to simply hand me the solution to this problem, thank you as that will solve my immediate problem. However, even if you can do this, please <em>please</em> provide an lmgfty that provides good web sites as references and/or a book or two that would provide a good education on this subject. Sites would be preferable as money is tight, but if a book is the solution, I'll find the money (assuming my local library system is unable to procure said volume).</p>