pattern-matching

Scope of variables inside scala’s case guard statement.

For lift development, I sometimes need to use match–case statements like the following. (Rewritten to plain scala for easier understanding.) One note to them: These are actually different partial functions, defined in different parts of the code, so it’s important that a case statement fails in or before the guard in order to have the ot...

Clojure replacement for ADTs and Pattern Matching?

Whenever in Haskell we need some variant data type, we would use ADTs in conjunction with pattern matching. What do Clojure folks use for such usecases? ...

Perl pattern matching

Hi All, I have a text file like this this is a junk line this is a junk line2 this is a junk line3 message1 this is first line of text this is second line of text this is third line of text this is fourth line of text this is fifth line of text message1_end the next line I want to start pattern match from message1 onwards and then pri...

patternplotting - java

hi, if we have 3 metrics ( attributes/vallues ) for 10 people (just an example). is it possible to find a pattern for the 10 people based on these 3 metrics and plot them? I am looking for doing this pattern matching in java. is there any library which can help me to do this in java??? The goal is to find different patterns which exist ...

Java library for detecting list items on webpages

Most of the webpages now-a-days contain lists of things, or chunks of html patterns that repeat a lot. For example: Facebook status messages on homepages. Digg/Hacker News StackOverflow homepage Is there a Java library for detecting such lists. It will involve some amount of pattern matching and intelligence. Thanks. ...

How do I parse a word between two elements?and extract it to database

let me brief there is a file (it might be anything sgml,xml,sgml etc).i will give that file as input and read the file using c#..so the job is now that i know that there are certain tags where in between this data is present...so the point is i have to scan that line by line like pattern matching and extract the data which is present i...

What is an efficient way to do pattern match in MySQL?

We have a huge pattern match in a query (about 12 strings to check). Now I have to do this query in MySQL, but it seems that the query from PostgreSQL has not the same syntax. From PostgreSQL: SELECT value FROM ... WHERE ... AND `value` !~* '.*(text|text2|text3|text4|text5).*'; How do I do this in MySQL in a efficient way? ...

Pattern matching html tags

Hello I'm new to pattern matching, having finally figured it out. I am stuck trying to find an approach to the following problem. I need to return a match (with php preg_match) if any of a number html tags are present. <p></p> <br> <h1></h1> <h2></h2> And return no match match otherwise. So anything not in the above list fails, e.g:...

Ocaml: how to pattern match on an arbitrary number of arguments?

Hi all, is there an OCaml equivalent to Haskell's pattern matching on an arbitrary number of arguments? For example, can I have something resembling: merge [] lst = lst merge lst [] = lst merge l1 @ (n : ns) l2 @ (m : ms) = if n < m then n : merge ns l2 else m : merge l1 ms (The example's lifted from Developing Applications with O...

Pattern recogntion - Magic the Gathering Card

I am hoping to create a program on my android (and/or more likely back at the server) to use the camera on the phone to capture an image of the card and break it into the corresponding parts and use them to identify the card to use in a database of my own creation. The pattern recognition is where I could use help. Ok, a card has a bla...

match pattern regex coldfusion

i need to match a pattern using reMatchNoCase("(listid)","listid car van listid dog cat listid house hotel")> so listid is the pattern and match that and everything to the next pattern witch is listid again. so if i dump the rematch ill get a structure each starting with listid and the content within this is what it should look like ...

How to use the rails match method with a string?

Is there a way to use the rails match method with a simple string, rather than a regular expression? I'm trying to match a url as such sometext.match('http://www.example.com') The problem is, this is stil getting evaluated as a regular expression, so I have to escape all the special characters for this to work properly, as such: some...

How to reference a val in a case statement?

I'm having a slow morning. I thought referencing an existing val in a case statement would be OK. But it seems it is interpreted as a local variable definition. A rudimentary googling didn't help and I don't have my staircase book with me. In the following, what is the syntax that would allow me to match on case (b,c)? scala> val (a,b,...

How to use switch/case (smiple pattern matching) in Scala?

I've found myself stuck on a very trivial thing :-] I've got an enum: object Eny extends Enumeration { type Eny = Value val FOO, BAR, WOOZLE, DOOZLE = Value } In a code I have to convert it conditionally to a number (varianr-number correspondence differs on context). I write: val en = BAR val num = en match { case FOO => ...

F# a function to check if a list is sorted or not

I have to write a function, that returns true if a given list is sorted in ascending order. The empty and 1-element lists are sorted. Also, [5,12,12] should return true. I've written a function that seems to work: let rec isSorted (l: int list) = match l with | [] -> true | [x] -> true | [x;y] -> x <= y | x::y::xr ...

Haskell Pattern Matching on Strings - Why doesn't this work?

getMultiWordPortion :: String -> String getMultiWordPortion (x:':':xs) = xs getMultiWordPortion _ = "" The expected result from pattern matching in this code is that everything before the first colon get's assigned to x, and everything afterwards gets assigned to xs, which is the result. If there is no colon, nothing is returned. What...

SQL Server LIKE containing bracket characters

Using SQL Server 2008. I have a table with the following column: sampleData (nvarchar(max)) The value for this column in some of these rows are lists formatted as follows: ["value1","value2","value3"] I'm trying to write a simple query that will return all rows with lists formatted like this, by just detecting the opening bracket....

Is there an API or algorithm that matches strings in a block of text and accounts for possible misspellings?

I'm looking for a solution that could process large blocks of user input text and match it against a set of strings that I've got stored in a database. The only problem is that the strings in the user input text are frequently misspelled. (The strings in the database are spelled correctly) I know modern search engines suggest results t...

SQL Server like statement issue

Hello everyone, I am using SQL Server 2008 Enterprise. Now I have two patterns to implement the same function (to see if zoo1 or zoo2 or zoo3 column contains some text, in pattern 1, I merge content of zoo1, zoo2 and zoo3 to form a new column called zoo), I think the first pattern is always of better performance (I have made some experi...

c# regular expression to match img src="*" type URLs.

I have a regex in c# that i'm using to match image tags and pull out the URL. My code is working in most situations. The code below will "fix" all relative image URLs to Absolute URLs. The issue is that the regex will not match the following: <img height="150" width="202" alt="" src="../Image%20Files/Koala.jpg" style="border: 0px solid...