pattern-matching

RegEx pattern to limit dashes in these circumstances

∥☆過路亽.° 提交于 2019-12-12 11:19:26
问题 Scenario I'm using a 3rd party file renaming software which is written in Delphi and has pascal-script support: http://www.den4b.com/?x=products&product=renamer The application allows the usage of regular expressions to rename files. this means that if what I need to do with a filename cannot be accomplished only using one RegEx, then I could use simultaneous various expressions or also a pascal-script code to accommodate the filename until I can properly format the filename for the needs of

SQL text before the Nth match?

为君一笑 提交于 2019-12-12 10:41:30
问题 Using SQL I'd like to return all text before the 3rd forward slash in a column so /one/two/three/whatever/testing would return: /one/two/three Any quick and dirty way to do this in SQL (specifically MS T-SQL under MS SQL 2005+) ? 回答1: Since you said "quick and dirty", I'm assuming that this very quick and very dirty solution won't receive a bunch of down votes. The SQL below uses multiple SUBSTRING() functions to find the third slash: DECLARE @str VARCHAR(50) SET @str = '/one/two/three

What is the difference between /* and /** pattern in Spring boot?

霸气de小男生 提交于 2019-12-12 10:38:01
问题 I was trying to register certain URLs for a Filter when I noticed that there is a difference between /* and /** patterns. @Bean public FilterRegistrationBean tokenAuthenticationFilterBean() { FilterRegistrationBean registration = new FilterRegistrationBean(tokenAuthenticationFilter); registration.addUrlPatterns("/api/**","/ping","/api/*"); return registration; } What is the difference between these patterns? 回答1: Spring normally uses ant-style path matching patterns for URLs - if you look at

F#: Destructuring bind with a discriminated union

你离开我真会死。 提交于 2019-12-12 10:36:51
问题 open System let x = (1, 2) let (p, q) = x printfn "A %A" x printfn "B %A %A" p q let y = Some(1, 2) try let None = y () with | ex -> printfn "C %A" ex let Some(r, s) = y printfn "D %A" y // printfn "E %A %A" r s http://ideone.com/cS9bK0 When I uncomment the last line, the compiler rejects the code complaining /home/rRiy1O/prog.fs(16,19): error FS0039: The value or constructor 'r' is not defined /home/rRiy1O/prog.fs(16,21): error FS0039: The value or constructor 's' is not defined Is it not

Restrict Pattern Matching to Subset of Constructors

和自甴很熟 提交于 2019-12-12 09:46:14
问题 Say I have the following: data Type = StringType | IntType | FloatType data Op = Add Type | Subtract Type I'd like to constrain the possible types under Subtract , such that it only allows for int or float. In other words, patternMatch :: Op -> () patternMatch (Add StringType) = () patternMatch (Add IntType) = () patternMatch (Add FloatType) = () patternMatch (Subtract IntType) = () patternMatch (Subtract FloatType) = () Should be an exhaustive pattern match. One way of doing this is to

Scala: Pattern matching when one of two items meets some condition

和自甴很熟 提交于 2019-12-12 08:26:36
问题 I'm often writing code that compares two objects and produces a value based on whether they are the same, or different, based on how they are different. So I might write: val result = (v1,v2) match { case (Some(value1), Some(value2)) => "a" case (Some(value), None)) => "b" case (None, Some(value)) => "b" case _ = > "c" } Those 2nd and 3rd cases are the same really, so I tried writing: val result = (v1,v2) match { case (Some(value1), Some(value2)) => "a" case (Some(value), None)) || (None,

Why does Scala warn about type erasure in the first case but not the second?

限于喜欢 提交于 2019-12-12 08:25:20
问题 I have two functions (not these have been edited since the original -- some of the answers below are responding to the original ones which returned a sequence of ()): def foo1[A](ls: Iterable[A]) : Iterator[A] = for (List(a, b) <- ls sliding 2) yield a def foo2[A](ls: Iterable[A]) : Iterator[A] = for (a::b::Nil <- ls sliding 2) yield a which I naively thought were the same. But Scala gives this waning only for the first one: warning: non variable type-argument A in type pattern List[A] is

Checking if a string consists of balanced parenthesis

一个人想着一个人 提交于 2019-12-12 08:24:38
问题 I wrote the following program to check strings for balanced parenthesis: isBalanced xs = isBalanced' xs [] isBalanced' [] [] = True isBalanced' [] _ = False isBalanced' ('(':xs) ys = isBalanced' xs (')':ys) isBalanced' ('[':xs) ys = isBalanced' xs (']':ys) isBalanced' ('{':xs) ys = isBalanced' xs ('}':ys) isBalanced' _ [] = False isBalanced' (x:xs) (y:ys) = (x == y) && (isBalanced' xs ys) Here is some example data: positives = [ isBalanced "", isBalanced "()", isBalanced "[]", isBalanced "{}"

Scala Map pattern matching

懵懂的女人 提交于 2019-12-12 08:08:42
问题 How to do pattern matching on a Map in Scala ? A (non working) attempt includes, Map("a"->1, "b"->2, "c"->3) match { case Map(a,b,_*) => a } which errs with value Map is not a case class, nor does it have an unapply/unapplySeq member case Map(a,b,_*) => a The error is indicative enough, yet how to enrich Map with an unapply method for pattern matching ? Many Thanks Update Following @Paul's comment, a neater use case may be like this, Map("a"->1, "b"->2, "c"->3) match { case Map("b"->2,_*) =>

How can i match Fingerprint from sqlite data base?

你说的曾经没有我的故事 提交于 2019-12-12 05:39:55
问题 I want to create one application which can match fingerprint form my server existing fingerprints, on my server side some fingerprints saved with the help of external fingerprint scanner. can i match with saved fingerprint? 回答1: Match in database You cannot match fingerprint in database, please read this : https://en.wikipedia.org/wiki/Fingerprint_recognition You have to match templates, thanks to a specific algorithm. To match on server, you need AFIS solution: https://en.wikipedia.org/wiki