pattern-matching

Regular Expression- Help needed

Dear All, I have a String template from which I need to get the list of #elseif blocks. For example the first #elseif block will be from #elseif ( $variable2 )Some sample text after 1st ElseIf. ,second #elseif block is from #elseif($variable2)This text can be repeated many times until do while is called. SECOND ELSEIF and so on. I'm...

javascript pattern replacement using backreference is not working

string.replace(/([\t])/g,"\\$1") is working fine where string.replace(/([\n])/g,"\\$1") is not working!!! any idea please??? N.B. string.replace(/\n/g,"\\n") is also working fine ...

Stable Matching Problem

I am currently reading an Algorithm's book and came across the Stable Matching Problem. And a question came to mind that I'm curious about, but the book doesn't answer. In every SMP is it possible to always have one pair where each prefers the other one the most? Like in the classic marriage example. Is there always a pair that have one ...

Pattern Matching a Haskell list of variable size

EDIT: I shouldn't be coding when this tired. I was compiling a different copy of the program than I was running. Sorry for wasting your time. I have the following code to make a single argument optional in my program's startup. main = do args <- getArgs handleArgs args handleArgs :: [String] -> IO () handleArgs (server:nick:ch...

Haskell Question on pattern matching

Hi everyone, I'm trying to write a function that takes in a list and returns true if it is in sorted order and false if not: So far what I have is: myordered [] = True myordered [x] = True myordered list1 | (head list1) <= (head (tail list1)) = myordered(tail list1) | otherwise = False Based on our ...

Match a regular expression against any non-character or number

Ok, here again. I'll promise to study deeply the regular expression soon :P Language: PhP Problem: Match if some badword exist inside a string and do something. The word must be not included inside a "greater word". I mean if i'll search for "rob" (sorry Rob, i'm not thinking you're a badword), the word "problem have to pass without ch...

Best approach for specific Object/Image Recognition task?

I'm searching for an certain object in my photograph: Object: Outline of a rectangle with an X in the middle. It looks like a rectangular checkbox. That's all. So, no fill, just lines. The rectangle will have the same ratios of length to width but it could be any size or any rotation in the photograph. I've looked a whole bunch ...

jquery regex replace from select text

I have some text I fetch inside here but only want the currency... How can I get rid of the other values? I tried this, but didn't have any luck. var symbol = $("div.price > h5 > div.num").text().replace(/[\d.]*/, ""); Here's the example html, the selector I'm using works fine, just not the replace. <div class="price"> <h5 c...

How do I use Haskell's type system to enforce correctness while still being able to pattern-match?

Let's say that I have an adt representing some kind of tree structure: data Tree = ANode (Maybe Tree) (Maybe Tree) AValType | BNode (Maybe Tree) (Maybe Tree) BValType | CNode (Maybe Tree) (Maybe Tree) CValType As far as I know there's no way of pattern matching against type constructors (or the matching functions i...

Java regex matching

I need to parse through a file(built from a string) searching for occurences of a single or multiline text. Will this solution always work ? If not - how should I change it ? private int parseString(String s){ Pattern p = Pattern.compile(searchableText); Matcher m = p.matcher(s); int count = 0; while(m.find()) { ...

MYSQL: Using GROUP BY with string literals

I have the following table with these columns: shortName, fullName, ChangelistCount Is there a way to group them by a string literal within their fullName? The fullname represents file directories, so I would like to display results for certain parent folders instead of the individual files. I tried something along the lines of: GRO...

.NET Regular Expression: How to get a text enclosed by two tags

Hello. I am working with ASP.NET and need to manage with a string typed by the user in order to extract some information. The user enters a normal text, words and numbers, but sometimes he may type a mathematical expression in MATHML, these expressions are always an xml string enclosed by the tag. I want to extract from the typed text e...

Pattern Matching in SQL Issue -- Finding the Right Query with PHP

Hello all. I'm in need of some quick help on matching a field in my database that stores all of the "parent" categories for my online store. Here's an example of how my "parents" are stored in the table via one field named Parent: MENS MENS-BRANDS MENS-SHIRTS MENS-T-SHIRTS Here is my query in PHP to perform the call: $query = "SELEC...

Fetching the matched string from the text using findstr

I have a text in some file like <Variable name="URL" value="http://url:port"/&gt; I want the url in the value tag( http://url:port ). The command and regex I'm using are FindStr /R /C:"\"URL\" *value=*\"*\"" <filename> The above regex matches the line in the file but fails to extract that url string any suggestion? ...

n-digit Pattern Matching in Lua

I'm new to Lua. Say i have a string "1234567890". I want to iterate over all possible 3 digit numbers. (ie 123,234,345,456....) for m in string.gmatch("1234567890","%d%d%d") do print (m) end But this gives me the output 123,456,789. What kind of Pattern should i be using? And secondly, a related question, how do i specify ...

How do I derive specific data from a string using the Java standard API?

I have the following pattern: Jan(COMPANY) &^% Feb(ASP) 567 Mar(INC) I want the final output to be: String[] one = {"Jan", "Feb", "Mar"}; String[] two = {"COMPANY","ASP","INC"}; Please help. Anyone!!? ...

Python: pattern matching for a string

Im trying to check a file line by line for any_string=any_string. It must be that format, no spaces or anything else. The line must contain a string then a "=" and then another string and nothing else. Could someone help me with the syntax in python to find this please? =] pattern='*\S\=\S*' I have this, but im pretty sure its wrong h...

Dynamic pattern matching

How can I do dynamic pattern matching in Erlang? Supose I have the function filter/2 : filter(Pattern, Array) where Pattern is a string with the pattern I want to match (e.g "{book, _ }" or "{ebook, _ }") typed by an user and Array is an array of heterogenous elements (e.g {dvd, "The Godfather" } , {book, "The Hitchhiker's Guide to t...

How do I check for if an exact string exists in another string?

I'm currently running into a bit of a problem. I'm trying to write a program that will highlight occurrences of a word or phrase inside of another string, but only if the string it's being matched to is exactly the same. The part I'm running into troubles with is identifying whether or not the subphrase I'm matching the phrase with is co...

n+k patterns in F#?

Hi all, I wrote the following in F#: let fib x = match x with | 0 -> 0 | 1 -> 1 | n+2 -> fib n + fib (n+1) Unfortunately, I got a compiler error stating I had used an infix operator in an unexpected place. Other than using the wildcard character, is there a way I can express my intent in F#? ...