pattern-matching

PostgreSQL substring get string between brackets

和自甴很熟 提交于 2019-12-04 03:11:20
问题 I have a string, say: Product Description [White] I want to extract anything inside the brackets (in this case White ) from that string, using the PostgreSQL Substring function. I can get this to work using regexp_matches , but that returns an array which I don't want unless I have no other choice. I've tried: substring('string' from '[(.)]') >>> NULL substring('string' from '\[(.)\]') >>> NULL substring('string' from '\\[(.)\\]') >>> NULL But this works: substring('string' from 'W(.)i]') >>>

SQL query to match one of multiple strings

牧云@^-^@ 提交于 2019-12-04 02:58:05
I have following data in table: +----------------------+----------------------------------------------------------+--------------+ | subscriber_fields_id | name | field_type | +----------------------+----------------------------------------------------------+--------------+ | 143 | Peshawar/Islamabad/Lahore/Swat/Mardan/Karachi | Job Location | | 146 | Karachi | Job Location | | 147 | Lahore and Karachi | Job Location | | 149 | Karachi, Mirpur Khas, Sukkur, Layyah, Gilgit, Charsaddah | Job Location | | 152 | Islamabad or Lahore | Job Location | | 155 | Islamabad | Job Location | | 157 | 7

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

自作多情 提交于 2019-12-04 02:16:35
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 unchecked since it is eliminated by erasure I think I understand why it gives that error for the first one

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

浪子不回头ぞ 提交于 2019-12-04 02:04:10
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, Some(value)) => "b" case _ = > "c" } But no luck. I encounter this problem in a few places, and this is

Windows scripting: list files not matching a pattern

感情迁移 提交于 2019-12-04 01:46:57
问题 In Windows 7 command prompt, I´d like to list all files of a folder which name does not start with abc . I have tried: forfiles /P C:\myFolder\ /M ^[abc]* /S /C "CMD /C echo @file" Where is my error? Many thanks. 回答1: Looking at forfiles /? : /M searchmask Searches files according to a searchmask. The default searchmask is '*' . which strongly suggests forfiles doesn't support regular expressions, just normal Cmd/Windows wildcards. On Windows 7 this can easily be achieved in PowerShell: dir c

How to save both matching and non-matching from grep

試著忘記壹切 提交于 2019-12-04 01:37:02
问题 I use grep very often and am familiar with it's ability to return matching lines (by default) and non-matching lines (using the -v parameter). However, I want to be able to grep a file once to separate matching and non-matching lines. If this is not possible, please let me know. I realize I could do this easily in perl or awk, but am curious if it is possible with grep. Thanks! 回答1: If it does NOT have to be grep - this is a single pass split based on a pattern -- pattern found > file1

Strange pattern matching behaviour with AnyRef

做~自己de王妃 提交于 2019-12-04 01:32:59
def test1(a: Any) = a match { case x: AnyRef => "AnyRef" case _ => "None of the above" } def test2(a: Any) = a match { case x: Double if x > 2 => "Double > 2" case x: AnyRef => "AnyRef" case _ => "None of the above" } Please can someone explain why in the following, the first case 1.0 matches on AnyRef , but in the second it doesn't. (Scala 2.9.0-1) scala> test1(1.0) res28: java.lang.String = AnyRef scala> test2(1.0) res29: java.lang.String = None of the above edit - Scala 2.10 update Jan 2013 : the new pattern matcher fixes this behaviour (or at least, makes it consistent) and the method

How do I use Java Regex to find all repeating character sequences in a string?

烂漫一生 提交于 2019-12-04 00:30:37
问题 Parsing a random string looking for repeating sequences using Java and Regex. Consider strings: aaabbaaacccbb I'd like to find a regular expression that will find all the matches in the above string: aaabbaaacccbb ^^^ ^^^ aaabbaaacccbb ^^ ^^ What is the regex expression that will check a string for any repeating sequences of characters and return the groups of those repeating characters such that group 1 = aaa and group 2 = bb. Also note that I've used an example string but any repeating

How to perform pattern matching with vararg case classes?

孤者浪人 提交于 2019-12-04 00:24:25
I have a set of case classes like this abstract class Shape case class Rectangle(width: Int, height: Int) extends Shape case class Location(x: Int, y: Int, shape: Shape) extends Shape case class Circle(radius: Int) extends Shape case class Group(shape: Shape*) extends Shape where basically Group is an array of shapes. I need to define a size method for computing sizes for rectangle, circle and location its straightforward just return one. But i am having difficulty for Group. object size extends Shape{ def size(s: Any) : Int = s match { case Rectangle(x,y) => 1 case Group // how to do it? Also

Google Sheets Pattern Matching/RegEx for COUNTIF

。_饼干妹妹 提交于 2019-12-04 00:24:01
The documentation for pattern matching for Google Sheets has not been helpful. I've been reading and searching for a while now and can't find this particular issue. Maybe I'm having a hard time finding the correct terms to search for but here is the problem: I have several numbers (part numbers) that follow this format: ##-#### Categories can be defined by the part numbers, i.e. 50-03## would be one product category, and the remaining 2 digits are specific for a model. I've been trying to run this: =countif(E9:E13,"50-03[123][012]*") ( E9:E13 contains the part number formatted as text. If I