<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr - noah</title>
<link>http://snipplr.com/users/noah/tags/regex</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Wed, 15 Feb 2012 01:24:53 GMT</pubDate>
<item>
<title>(Perl) Search and Replace Across Multiple Files with Perl</title>
<link>http://snipplr.com/view/19732/search-and-replace-across-multiple-files-with-perl/</link>
<description><![CDATA[ <p>This brief script *replaces* the batch search-and-replace tool in your commercial text editor.  If batch file search and replacement is the only reason you need an IDE, you can adopt this script and go back to using Notepad (or better yet `vi`).

Thanks to JPinyan, who taught me the pattern shown below, back in 2001 on `beginners.perl.org`

The regular expression flags used here are explained in excellent detail in the *best practices for regular expressions* chapter of **Perl Best Practices** by Damian Conway.</p> ]]></description>
<pubDate>Tue, 15 Sep 2009 00:18:30 GMT</pubDate>
<guid>http://snipplr.com/view/19732/search-and-replace-across-multiple-files-with-perl/</guid>
</item>
<item>
<title>(Perl) Fuzzy string matching with Perl</title>
<link>http://snipplr.com/view/16365/fuzzy-string-matching-with-perl/</link>
<description><![CDATA[ <p>Fuzzy string matches with Jarkko Hietaniemi's String::Approx module.

**Get approximate matches, close to what you want.**  This is great for when you have filenames that might contain misspellings, extra underscores or other typos and mistakes.  Also great for searching for files when there are several different naming conventions used within a project.

Mainly I am concerned with being able to match strings that have underscores inserted (or deleted) in arbitrary places.  But the result I came up with here, does a pretty good job of matching when there are all sorts of typos, without picking up *too* many false positives.</p> ]]></description>
<pubDate>Sat, 27 Jun 2009 01:09:08 GMT</pubDate>
<guid>http://snipplr.com/view/16365/fuzzy-string-matching-with-perl/</guid>
</item>
<item>
<title>(JavaScript) Use a variable in a JavaScript regular expression</title>
<link>http://snipplr.com/view/15357/use-a-variable-in-a-javascript-regular-expression/</link>
<description><![CDATA[ <p>Use the `RegExp` constructor to create the regular expression.  You can pass `RegExp` any string as an argument and it will be converted to a regex.</p> ]]></description>
<pubDate>Wed, 27 May 2009 11:48:31 GMT</pubDate>
<guid>http://snipplr.com/view/15357/use-a-variable-in-a-javascript-regular-expression/</guid>
</item>
<item>
<title>(Perl) grep with Perl</title>
<link>http://snipplr.com/view/11878/grep-with-perl/</link>
<description><![CDATA[ <p>A combination of the instructions in the book _Minimal Perl_ and [this Perl one-liners page](http://sial.org/howto/perl/one-liner/)

The general form of the one-liner is:

    > perl -wnl -e '/REGEX/ and print $ARGV." $.: $_"; close ARGV if eof' 

The example below shows how to print the hex colors that are defined in a [Sass](http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html) source tree.</p> ]]></description>
<pubDate>Thu, 05 Feb 2009 13:29:59 GMT</pubDate>
<guid>http://snipplr.com/view/11878/grep-with-perl/</guid>
</item>
<item>
<title>(Ruby) How to find the path to the script that is currently executing</title>
<link>http://snipplr.com/view/11032/how-to-find-the-path-to-the-script-that-is-currently-executing/</link>
<description><![CDATA[ <p>I just realized this kind of  regex operation is done with slice in Ruby.  In Perl that would be 

    print 'path/to/file' =~ m{(.*/)};</p> ]]></description>
<pubDate>Fri, 09 Jan 2009 09:12:14 GMT</pubDate>
<guid>http://snipplr.com/view/11032/how-to-find-the-path-to-the-script-that-is-currently-executing/</guid>
</item>
<item>
<title>(JavaScript) Alter an existing, hard-coded onclick function</title>
<link>http://snipplr.com/view/10273/alter-an-existing-hardcoded-onclick-function/</link>
<description><![CDATA[ <p>Get the existing hardcoded function, convert it to a string, edit the string.
Then strip the string down to just the function body, re-instantiate the string into a function, and assign it back to the onclick handler.

The code here is extremely site-specific.  Here's what the original onclick function I was working against looked like:

    new Ajax.Request('/publications?categories%5B%5D=1,2,3', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('6b670face4ca93ce4bf53def7685d8663780b7d9')}); return false;

The code below just changes the query string in the first parameter.  The idea being that you have a bunch of checkboxes with IDs like foo-1, foo-2, and you want that query pram to reflect the number thats appended to the end of each checkbox's ID.  

Not that you want to do that :)  But hey, these kinds of situations sometimes come up in production.   Anyway, the **interesting bit** is JavaScript's ability to **break a function down into a string, edit the string, and then re-instantiate the string as a new function,** possibly overriding the original.

Functions as data: Mmmm... Lispy.

Tested only in Firefox 3 but should work in any browser.</p> ]]></description>
<pubDate>Thu, 04 Dec 2008 19:12:10 GMT</pubDate>
<guid>http://snipplr.com/view/10273/alter-an-existing-hardcoded-onclick-function/</guid>
</item>
<item>
<title>(Perl) Clean up Word documents that have been translated to HTML</title>
<link>http://snipplr.com/view/9483/clean-up-word-documents-that-have-been-translated-to-html/</link>
<description><![CDATA[ <p>Haven't tried this with any recent versions of Word.  Yet.</p> ]]></description>
<pubDate>Tue, 04 Nov 2008 09:54:38 GMT</pubDate>
<guid>http://snipplr.com/view/9483/clean-up-word-documents-that-have-been-translated-to-html/</guid>
</item>
<item>
<title>(Emacs Lisp) HAML conversion Emacs macros</title>
<link>http://snipplr.com/view/9366/haml-conversion-emacs-macros/</link>
<description><![CDATA[ <p>Some utility functions I was working on just before [I discovered html2haml.](http://groups.google.com/group/haml/browse_thread/thread/ce7ec76d772552e9?pli=1 "html2haml converts html to haml")</p> ]]></description>
<pubDate>Wed, 29 Oct 2008 23:48:40 GMT</pubDate>
<guid>http://snipplr.com/view/9366/haml-conversion-emacs-macros/</guid>
</item>
<item>
<title>(Bash) grep for either of two strings</title>
<link>http://snipplr.com/view/6819/grep-for-either-of-two-strings/</link>
<description><![CDATA[ <p>Here's an example of using grep to filter for links that contain the string 'jpg' or 'gif'</p> ]]></description>
<pubDate>Fri, 20 Jun 2008 15:29:33 GMT</pubDate>
<guid>http://snipplr.com/view/6819/grep-for-either-of-two-strings/</guid>
</item>
<item>
<title>(Ruby) Regex replace</title>
<link>http://snipplr.com/view/5560/regex-replace/</link>
<description><![CDATA[ <p>Equivalent of the Perl code: url =~ s/foo/bar/</p> ]]></description>
<pubDate>Tue, 25 Mar 2008 14:09:21 GMT</pubDate>
<guid>http://snipplr.com/view/5560/regex-replace/</guid>
</item>
<item>
<title>(Bash) Tail requests for HTML files</title>
<link>http://snipplr.com/view/4069/tail-requests-for-html-files/</link>
<description><![CDATA[ <p>This command will tail an Apache access log, but only print lines where an HTML file was requested.</p> ]]></description>
<pubDate>Mon, 05 Nov 2007 12:40:54 GMT</pubDate>
<guid>http://snipplr.com/view/4069/tail-requests-for-html-files/</guid>
</item>
<item>
<title>(JavaScript) Kruse's hasClass</title>
<link>http://snipplr.com/view/3337/kruses-hasclass/</link>
<description><![CDATA[ <p>This Matt Kruse's hasClass function.</p> ]]></description>
<pubDate>Fri, 20 Jul 2007 19:06:22 GMT</pubDate>
<guid>http://snipplr.com/view/3337/kruses-hasclass/</guid>
</item>
<item>
<title>(Perl) search and replace across multiple files with Perl</title>
<link>http://snipplr.com/view/3145/search-and-replace-across-multiple-files-with-perl/</link>
<description><![CDATA[ <p>A couple of useful snippets from an article I found at Perl.com

**Perl search-and-replace on the command line.**

All of these should be usable under Cygwin as well.  But remember that bash wants single-quoted strings but MS-DOS shell wants strings to be double-quoted.</p> ]]></description>
<pubDate>Wed, 04 Jul 2007 20:00:52 GMT</pubDate>
<guid>http://snipplr.com/view/3145/search-and-replace-across-multiple-files-with-perl/</guid>
</item>
<item>
<title>(Perl) scraper</title>
<link>http://snipplr.com/view/3131/scraper/</link>
<description><![CDATA[ <p>For a while I used this to scrape weather.com.  Then they changed their HTML and my script broke.</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 22:48:36 GMT</pubDate>
<guid>http://snipplr.com/view/3131/scraper/</guid>
</item>
<item>
<title>(Perl) id3.pl</title>
<link>http://snipplr.com/view/3129/id3pl/</link>
<description><![CDATA[ <p>This script takes a list of directories as its argument. 
  For mp3s that don't have any id3 information, guess      
  the name of the artist and track based on the filename   
  and use the MP3-Info module to insert that guess into    
  the file as id3v1 tags.</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 22:40:18 GMT</pubDate>
<guid>http://snipplr.com/view/3129/id3pl/</guid>
</item>
<item>
<title>(Perl) Truncate filenames but keep file extensions intact</title>
<link>http://snipplr.com/view/3127/truncate-filenames-but-keep-file-extensions-intact/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 03 Jul 2007 22:33:28 GMT</pubDate>
<guid>http://snipplr.com/view/3127/truncate-filenames-but-keep-file-extensions-intact/</guid>
</item>
<item>
<title>(Perl) Remove duplicate lines from a text file with Perl</title>
<link>http://snipplr.com/view/3124/remove-duplicate-lines-from-a-text-file-with-perl/</link>
<description><![CDATA[ <p>*[Found at Google Answers.](http://answers.google.com/answers/threadview?id=25196)*

Sometimes I get a big list of things, and some of the things occur multiple times in the same list.  To make the list easier to read, I want to *delete* the duplicate lines.
 
A good example is a list of files that have errors (maybe excerpted from an application sever's log files).  In that case you have a newline-delimited list of file paths,  and depending upon the situation, the same file path might be listed 4 or 5 times or more.  Often, it is useful to have a list of just the files that are faulty, which can be produced by deleting all the duplicate lines.  This script is for filtering just those kinds of list files.

[Of course,](http://xkcd.com/378/ "emacs has a command for that")  for **Emacs** users  [there is a much easier way to remove duplicate lines:](http://everything2.com/title/useful%2520emacs%2520lisp%2520functions "useful emacs lisp functions"), if you have `uniq` installed on your system.

`M-x sort-lines RET C-x h M-x shell-command-on-region RET uniq RET`</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 22:06:34 GMT</pubDate>
<guid>http://snipplr.com/view/3124/remove-duplicate-lines-from-a-text-file-with-perl/</guid>
</item>
<item>
<title>(Perl) Show JPEGs in this directory all on one page</title>
<link>http://snipplr.com/view/3122/show-jpegs-in-this-directory-all-on-one-page/</link>
<description><![CDATA[ <p>Dumps a list of image names into an HTML document, wrapped in centered IMG tags.  Features the CENTER tag for added historical value.</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 21:57:11 GMT</pubDate>
<guid>http://snipplr.com/view/3122/show-jpegs-in-this-directory-all-on-one-page/</guid>
</item>
<item>
<title>(Perl) show JPEGs in this directory in a simple HTML gallery</title>
<link>http://snipplr.com/view/3121/show-jpegs-in-this-directory-in-a-simple-html-gallery/</link>
<description><![CDATA[ <p>Creates an HTML page with the first image in the directory in the center.  Forward and Back buttons scroll through all the images in the directory in order.

This is how I lived before Firefox ~.^</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 21:53:26 GMT</pubDate>
<guid>http://snipplr.com/view/3121/show-jpegs-in-this-directory-in-a-simple-html-gallery/</guid>
</item>
<item>
<title>(Perl) Examine CSS selectors in JSP files and report on whether they match some patterns</title>
<link>http://snipplr.com/view/3119/examine-css-selectors-in-jsp-files-and-report-on-whether-they-match-some-patterns/</link>
<description><![CDATA[ <p>Processe a directory of JSP source files, looks for regex matches, and reports on the number and location of matches.  For detecting deprecated attributes in XHTML.

Uses Mail::Outlook to send an email.  Requires you to click "ok" each time a notification is sent, but gets around firewalls.</p> ]]></description>
<pubDate>Tue, 03 Jul 2007 21:27:59 GMT</pubDate>
<guid>http://snipplr.com/view/3119/examine-css-selectors-in-jsp-files-and-report-on-whether-they-match-some-patterns/</guid>
</item>
</channel>
</rss>
