I'm new to writing regular expressions. Please Help

Re: I'm new to writing regular expressions. Please Help

So pages you want to download from are these:

http://www.ethnic-gallery.com/africa/Senegal/index2.htm
http://www.ethnic-gallery.com/america/achomawi/

Here's how I created the script for them:

  1. I went to that Africe page.
  2. Started ThumbsDown Script Wizard.
  3. Selected two thumbnails to work with in the Script Wizard. (use Ctrl + click to select multiple thumbnails)
  4. Worked my way through the wizard mostly by clicking Next as the values that wizard suggested were ok.

As a result I got:

name: ethnic-gallery.com
matcher: http://www\.ethnic-gallery\.com/africa/Senegal/source/africa-ethnic-senegal-0\d+\.htm
type: RegExp 
source: Thumbnail
pattern: http://www\.ethnic-gallery\.com/africa/Senegal/preview/africa-ethnic-senegal-0(\d+)\.jpg
template: http://www.ethnic-gallery.com/africa/Senegal/source/image/africa-ethnic-senegal-0$1.jpg

That's a working script for that first page. To get it working on the America page also:

  1. I went to that America page
  2. Started ThumbsDown Script Wizard.
  3. Selected again two thumbnails to work with in the Script Wizard.
  4. Chose to modify the existing 'ethnic-gallery.com' script, instead of creating a new one.
  5. Matcher required changing but nothing complex. Basically \w matches a letter, number and underscore, and \w+ matches a one or more of them. The existing matcher had also a dash, which \w doesn't match, so we use a set of characters. [-\w]+ matches one or more dash, letter, number and underscore.
  6. Similar changes were required in pattern and template. The existing script already had one capture: (\d+) in pattern, $1 in template. Now have to just add a couple more.

Result:

name: ethnic-gallery.com
matcher: http://www\.ethnic-gallery\.com/\w+/\w+/source/[-\w]+\.htm
type: RegExp 
source: Thumbnail
pattern: http://www\.ethnic-gallery\.com/(\w+)/(\w+)/preview/([-\w]+)\.jpg
template: http://www.ethnic-gallery.com/$1/$2/source/image/$3.jpg

That scripts works on both pages. And if you come across page in ethnic-gallery.com where that script doesn't work, just open up Script Wizard and tweak the regular expressions.

Here are some links to help you with regular expressions:

http://thumbsdown.mozdev.org/regexp.html#introduction
http://www.regular-expressions.info/
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Globa...

I hope that helps. I suggest you try to create the script by yourself as I did in the above and not just copy the final script. You learn more about how ThumbsDown and regular expressions work. Ask if you have problems.