pattern-matching

SQL Server 2008 R2 - Scalar UDF results in infinite loop

我只是一个虾纸丫 提交于 2019-12-24 17:50:21
问题 The following code is resulting in an infinite loop or really really slow execution: CREATE FUNCTION [dbo].[CleanUriPart] ( -- Add the parameters for the function here @DirtyUriPart nvarchar(200) ) RETURNS nvarchar(200) AS BEGIN; -- Declare the return variable here DECLARE @Result nvarchar(200); DECLARE @i int; SET @i = 1; WHILE 1 = 1 BEGIN; SET @i = PATINDEX('%[^a-zA-Z0-9.~_-]%', @DirtyUriPart COLLATE Latin1_General_BIN); IF @i > 0 SET @DirtyUriPart = STUFF(@DirtyUriPart, @i, 1, '-'); ELSE

pattern match in Erlang

ぃ、小莉子 提交于 2019-12-24 17:46:25
问题 I am trying to learn some Erlang while I got stuck on these several Erlang pattern matching problems. Given the module here: -module(p1). -export([f2/1]). f2([A1, A2 | A1]) -> {A2, A1}; f2([A, true | B]) -> {A, B}; f2([A1, A2 | _]) -> {A1,A2}; f2([_|B]) -> [B]; f2([A]) -> {A}; f2(_) -> nothing_matched. and when I execute p1:f2([x]) , I received an empty list which is [] . I thought it matches the 5th clause? Is that a literal can also be an atom? When I execute p1:f2([[a],[b], a]) , the

Calculate mathematical operation stored in String using regex in Scala

天大地大妈咪最大 提交于 2019-12-24 17:19:59
问题 I want to evaluate mathematical expression stored in String and print the result. I have to use Pattern matching in Scala. I wrote this code below, but it does not work, it prints false instead of 2 . Any help will be appreciated. object PatternMatcher{ val s = "13 - 5 - 6" val Pattern = "((\\d+\\s[+-]\\s){1,10}(\\d+){0,1})".r def main(args: Array[String]) { println(matcher(s)) } def matcher(choice: String): Any = choice match { case Pattern(choice) => choice case _ => "false" } } 回答1: If you

parse using pattern matching in shell

大兔子大兔子 提交于 2019-12-24 12:34:18
问题 I am trying to use reqex, pattern matching, to split this string in to separate variables, abc12c20m . where: var1=abc var2=12 var3=20 Main string could differ for exp abc2c5m , but abc part is always the same and c and m are always in the string. One solution must work for both abc12c20m and abc2c5m . Any help will be greatly appreciated. 回答1: You can use BASH regex: s='abc12c20m' if [[ "$s" =~ ^(abc)([0-9]+)c([0-9]+)m$ ]]; then var1=${BASH_REMATCH[1]} var2=${BASH_REMATCH[2]} var3=${BASH

Linq Pattern Matching

血红的双手。 提交于 2019-12-24 10:48:31
问题 I am using Regular Expression for matching patterns say example in the follwoing example i am matching string to count vowels. void VowelsCountInEachWord() { Regex rx = new Regex("[aeiou]"); var words=new string[] {"aesthetic", "benevolent", "abstract", "capricious", "complacent", "conciliatory", "devious", "diligent", "discernible","dogmatic", "eccentric","fallacious","indifferent","inquisitive", "meticulous","pertinent","plausible", "reticent" }; var filter = from w in words where (rx

Efficiently replacing a string or character from file-input for the ANTLRInputStream (ANTLRStringStream)

喜你入骨 提交于 2019-12-24 10:47:54
问题 As I described in Antlr greedy-option I have some problems with a language that could include string-literals inside a string-literal, such as: START: "img src="test.jpg"" Mr. Bart Kiers mentioned in my thread that it is not possible to create a grammar which could solve my problem. Therefore I decided to change the language to: START: "img src='test.jpg'" before starting the lexer (and parser). File-input could be: START: "aaa"aaa" "aaa"aaaaa" :END_START START: "aaa"aaa" "aaa"aa a aa" :END

Use of moved value when pattern matching an enum with multiple values after downcasting

╄→尐↘猪︶ㄣ 提交于 2019-12-24 10:39:31
问题 I can use pattern matching on an enum that has one String parameter: extern crate robots; use std::any::Any; use robots::actors::{Actor, ActorCell}; #[derive(Clone, PartialEq)] pub enum ExampleMessage { Msg { param_a: String }, } pub struct Dummy {} impl Actor for Dummy { // Using `Any` is required for actors in RobotS fn receive(&self, message: Box<Any>, _context: ActorCell) { if let Ok(message) = Box::<Any>::downcast::<ExampleMessage>(message) { match *message { ExampleMessage::Msg { param

Pattern Matching a Haskell list of variable size

血红的双手。 提交于 2019-12-24 09:17:28
问题 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:channel:[]) = IRC.startIRC server 6667 nick channel handleArgs (server:port:nick:channel:[]) = IRC.startIRC server (read port :: Int) nick channel handleArgs _ = putStrLn

Match Anything In Between Strings For Linux Grep Command

你。 提交于 2019-12-24 09:04:07
问题 I have read the post grep all characters including newline but I not working with XML so it's a bit different with my Linux command. I have the following data: Example line 0</span> <tag>Example line 1</tag> <span>Example line 1.5</span> <tag> Example line 2 </tag> Example line 3 <span>Example line 4</span> Using this command cat file.txt | grep -o '<tag.*tag>\|^--.*' I get: <tag>Example line 1</tag> However, I want the output to be: <tag>Example line 1</tag> <tag>Example line 2</tag> How can

Java: Find the number of times a word is present in a String (is there something similar to expression of C#)?

北慕城南 提交于 2019-12-24 08:33:48
问题 I am interesting in finding the number of times a word appears in a String. I have seen the example of SUN Matcher Demo using the matcher (constructs a regex and counts the groups). I was interested if this is the only way or there is something else like e.g. Regex.Matches( input, "true" ).Count in C# (from SO question). Or in my context: If I am in a loop using contains to check if certain words in the List appear in the String is there a simple/elegant way to get (on the spot??) the number