pattern-matching

[Haskell] Conflicting Definitions in Pattern Matching

I just started learning Haskell and I ran into a problem in 2-adic type classes. Here's the important code: data Rectangle = NoRect | Rect (Float,Float) (Float,Float) | Pane deriving (Show) class Collision s1 s2 where collides :: s1 -> s2 -> Bool instance (Collision Rectangle Rectangle) where collides (Rect (aOrX, aOrY...

What's the name of the Makefile 'match' special variable?

What is the name of the special Makefile variable that contains the match of %, to use in the rule body? As an example, I would like to use it like this: %.o: %.c @echo Matched $MATCH $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ where I put $MATCH there because I can't remember the actual name of that special pa...

Regex in preg_replace to detect url format and extract elements

I need to replace certain user-entered URLs with embedded flash objects...and I'm having trouble with a regex that I'm using to match the url...I think mainly because the URLs are SEO-friendly and therefore a bit more difficult to parse URL structure: http://www.site.com/item/item_title_that_can_include_1('_etc-32CHARACTERALPHANUMERICGU...

pattern findings using "find" in Rails

Hi, This is my current code @descriptions = TableName.find(:first, :conditions=> ["table_id = ?", table_name.table_id], :order => 'author_year') author_year column contains data of kannan 1845 kohlun 1976 palani 1956 Using above code, it gives result with order of author_year based on author names. I need to order the query asce...

String pattern matching problem

Imagine we have a long string containing the substrings 'cat' and 'dog' as well as other random characters, eg. cat x dog cat x cat x dog x dog x cat x dog x cat Here 'x' represents any random sequence of characters (but not 'cat' or 'dog'). What I want to do is find every 'cat' that is followed by any characters except 'dog' and the...

Pattern Matching

I am goingto be starting work soon on a new project at work. Essentially there are many chemical compounds here each has its own prefix / identifier. For example a couple of chars followed by a few ints and that sort of thing, tho they all vary. I was wondering if there was an algorithm for matching these elements efficiently, opposed t...