pattern-matching

Safe regexs to clean serialized DOM?

我怕爱的太早我们不能终老 提交于 2019-12-10 23:17:08
问题 I'm after several, really safe regex patterns for JavaScript's .replace method. The input is a serialized DOM string, and I am wanting to remove all YUI3 classNames and YUI3 generated id attributes. var resourceDOMStr = Y.DataType.XML.format( Y.Node.getDOMNode(this.getIframeDOMContainer()).innerHTML ); alert('unsanitized markup:\n\n'+resourceDOMStr ); // Remove YUI-added id's and classes // regex to remove ' id="*"' // regex to remove entire class attr: ' class="'yui3-*'"' // regex to remove

Using Response in the same PHP file

女生的网名这么多〃 提交于 2019-12-10 23:07:47
问题 I have a one single PHP file in which first part: Server generates some output. Second Part:uses the server generated output and submits the information. what i have done: File Name: abc.php <?php //first part based on the information here server generates some output say: 111 success: id:104.123/12345678 |value:10000045 //second part i will be using the output generated in the first part. what i have done is something like this $server_said = file_get_contents('http://http://abc.php'); //abc

sed help: matching and replacing a literal “\n” (not the newline)

依然范特西╮ 提交于 2019-12-10 21:33:28
问题 i have a file which contains several instances of \n . i would like to replace them with actual newlines, but sed doesn't recognize the \n . i tried sed -r -e 's/\n/\n/' sed -r -e 's/\\n/\n/' sed -r -e 's/[\n]/\n/' and many other ways of escaping it. is sed able to recognize a literal \n ? if so, how? is there another program that can read the file interpreting the \n 's as real newlines? 回答1: Can you please try this sed -i 's/\\n/\n/g' input_filename 回答2: $ echo "\n" | sed -e 's/[\\][n]

Haskell error: “non-exhaustive patterns”

佐手、 提交于 2019-12-10 21:18:56
问题 So i have this function and when i try to use it like this: mergeSortedLists [1,1] [1,1] it gives me an error: [1,1*** Exception: SortFunctions.hs:(86,1)-(91,89): Non-exhaustive patterns in function mergeSortedLists 85 mergeSortedLists :: (Ord t) => [t] -> [t] -> [t] 86 mergeSortedLists [] [] = [] 87 mergeSortedLists (x:[]) [] = x:[] 88 mergeSortedLists [] (y:[]) = y:[] 89 mergeSortedLists (x:[]) (y:[]) = (max x y) : (min x y) : [] 90 mergeSortedLists (x:tail1) (y:tail2) | x > y = x :

Pattern matching with identical wildcards

帅比萌擦擦* 提交于 2019-12-10 20:42:24
问题 I'm working with PostgreSQL and want to know whether you can have a wildcard retain its value. So for example say I had select * from tableOne where field like ‘_DEF_’; Is there a way to get the first and last wildcard to be the exact same character? So an example matching result could be: ADEFA or ZDEFZ. 回答1: You can use a regular expression with a back-reference: select * from some_table where some_column ~* '^(.)DEF(\1)$' ^(.)DEF(\1)$ means: some character at the beginning followed DEF

F# odd pattern matching issues

拥有回忆 提交于 2019-12-10 20:12:38
问题 While writing some code yesterday, I ran into two odd problems, which neither me nor my functional programming oriented friend could figure out. We have looked at it for quite some time, and researched it on the net, but we were not able to find any answers anywhere, so here goes: The issue is that in this code: First weird problem: let outer1 (bs : byte array) = let rec inner (bs : byte array) (bacc : byte array) (i : int) = match i with | bs.Length -> bacc // <--- Error: bs is not

Wildcard for type when matching discriminated unions

随声附和 提交于 2019-12-10 20:03:58
问题 In the following real world example I do a match: type Style = Nice | Cool | Ugly type Color = Blue | Yellow | Orange | Grey | Cyan type ClothingProperties = Style * Color type Clothes = | Jeans of ClothingProperties | Pullover of ClothingProperties | Shirt of ClothingProperties type Person = | Person of string * Clothes let team = [Person("Jan", Jeans (Cool, Blue)); Person("Pete", Shirt (Nice, Cyan)); Person("Harry", Pullover (Ugly, Grey))] let matchPerson person= match person with | Person

enrich PartialFunction with unapply functionality

筅森魡賤 提交于 2019-12-10 18:56:06
问题 PartialFunction is a natural extractor, its lift method provides exact extractor functionality. So it would be very convenient to use partial functions as extractors. That would allow to combine pattern matching expressions in more complicated way than plain orElse that is available for PartialFunction So I tried to use pimp my library approach and had failed Here goes update : As @Archeg shown, there is another approach to conversion that works. So I'm including it to the provided code. I'm

OCaml Pattern match with non-constants

白昼怎懂夜的黑 提交于 2019-12-10 18:51:56
问题 Is it possible to do pattern matching on variables instead of constant values: # let x = 2 in let y = 5 in match 2 with | x -> "foo" | y -> "bar" | _ -> "baz";; let y = 5 in Warning 26: unused variable y. let x = 2 in Warning 26: unused variable x. | y -> "bar" Warning 11: this match case is unused. | _ -> "baz";; Warning 11: this match case is unused. - : string = "foo" Obviously, with this syntax, the x -> "foo" case takes everything. Is there a way to make it be equivalent to: match 2 with

Determining type on the fly in OCaml's OOP construct

本秂侑毒 提交于 2019-12-10 18:07:58
问题 I am learning about OCaml's OOP constructs and partially implemented this today until I realized I have no idea how to represent a polymorphic match statement without using the type keyword outside of the object. class bar (param:string) = object (code) end;; class foo param = object (code) initializer match param with string -> Printf.printf "param is a string" | bar -> Printf.printf "param is a bar" end;; let b = new bar "a string";; let f1 = new foo "test";; let f2 = new foo b;; Is it