Show HN: RegEx for Regular Folk – A visual, example-based introduction
I think what regex's need is a really powerful syntax and language aware regex editor.<p>I've been using regexs for most of my career, and still struggle to get them right on first writing.<p>The #1 problem I run into is:<p>what is a literal character and what is a control character?<p>for example, both these are very common:<p>- match a parenthesis character or a period character<p>- use a parenthesis to group a match or use a period to match any one character<p>You would think I would learn it once, and be good.<p>but my #2 problem confounds this:<p>what is a literal character and what is a control character - in the language I am using?<p>for example I might need to escape a period to make it a literal for a regex.<p>If I am checking the files filexc and file.c and want to match the second, the regex I want is<p><pre><code>  ^.*\.c$
</code></pre>
in perl, I could say:<p><pre><code>  $rx = "^.*\\.c\$";    ($" is a thing)
  if ($f =~ /$regex/) { ...
</code></pre>
better would be:<p><pre><code>  if ($f =~ /^.*\.c$/) {...
</code></pre>
in python I would write<p><pre><code>  m = re.search("^.*\\.c$",f)
</code></pre>
better would be:<p><pre><code>  m = re.search(r'^.*\.c$', f)
</code></pre>
in a shell script, I might say:<p><pre><code>  grep "^.*\\.c$"
</code></pre>
EDIT: crap, I had to escape <i>my comment</i> because the asterisk in the regex was making my text italic