Questions tagged [pattern-matching]

Use this tag for questions about testing whether a data structure has a particular shape or contains particular values in certain locations. Many functional languages provide pattern matching constructs. Most questions in this tag should also have the tag for the language you are programming in. Do not use this tag for regular expression questions, use regex tag instead; similarly, for pattern matching (globbing) in POSIX-like shells, use glob tag.

0
votes
1answer
16 views

Regular Expression - Starts With Value or After Second Comma Starts With Value

I'm trying to develop a regular expression that has this logic: if(startsWith(value) || afterSecondCommaStartsWith(value)) {} I have a string like: Thomas Municipal Court, Creber, Lester County, ...
2
votes
1answer
100 views

Haskell why using @ (as)

Came across this example: buildEntry ws@(w:_) = (w, length ws) What's the advantage of using ws@(w:_) instead of: buildEntry' (w:ws) = (w, length (w:ws)) Since I am only a beginner, I think ...
0
votes
2answers
29 views

SQL join table on partial string

I have two tables in a Postgres database: Table A: **Middle_name** John Joe Fred Jim Bob Paul-John Table B: **Full_name** Fred, Joe, Bobda Jason, Fred, Anderson Tom, John, Jefferson Jackson, Jim ...
1
vote
0answers
21 views

String.match in read mode *line [on hold]

I have a problem when using string.match in read mode line file:read('*line') For example, case 1 : str = print([[this is line breaks]]) Result : str:match('print') --print([[this is I've tried ...
1
vote
1answer
43 views

Java – Regex – match opening and closing curly tags

I want to capture a text like this: {ul} {li}Item 1{/li} {li}Item 2{/li} {li}Item 3{/li} {/ul} {img}this_is_an_image{/img} {p}paragraph text {/p} {h2}Heading{/h2} And turn it into an ...
0
votes
1answer
12 views

Scala XML, delete node by pattern matching

Hi i have a big xml file where i want to delete certain node, using pattern matching. A part of the xml looks like this: <ddm:relation scheme="STREAMING_SURROGATE_RELATION">/path/to/somewhere/$...
-2
votes
1answer
46 views

Is there any way to do partial String matching in R?

I have 2 data frames. First has more number of rows and one ID column "ALP23456" and other related columns. Second has lesser number of rows and the ID value is present as a comment "ALP23456 done on ...
1
vote
1answer
34 views

Returning different state of Discriminate union based upon string input in pattern match (F#)

type ColType = I of int | S of string | F of float I know that you cannot return a different type from a pattern match which is why I made this type in the first place for a parser I am creating. ...
0
votes
1answer
21 views

Get a number present after a particular pattern of a matching string which consists of word and number

This is the input string: text Expedien N0 18-00232995 $cat input_file some text before Expedien: 1-21-212-16-26 some random text Reference RE9833 of all sentences. abc 123 456 something blah blah ...
1
vote
1answer
31 views

How do you extract the value from multiple variants of a custom type?

I have a type like, type Post = Blog String String | Announcement String String And a function like, upcaseTitle : Post -> Post upcaseTitle post = case post of Blog title ...
-1
votes
1answer
13 views

Will a clustering method solve this noisy matching problem?

Suppose that there are four lists of data, and the dimension of each data point is three. Each list is generated from a different method. Ideally, only one data point in each list is equivalent to the ...
1
vote
2answers
40 views

Troubles with collections type in pattern matching in Scala

I tried to do collection matching in Scala without using scala.reflect.ClassTag case class Foo(name: String) case class Bar(id: Int) case class Items(items: Vector[AnyRef]) val foo = Vector(Foo("a"),...
0
votes
1answer
44 views

Java Regex: What will be the regular expression for pattern like “10{1,1 %d},10{2,1 %d}”?

Consider following example: Regex: (.\*?),(.\*) String: 10,20 Result: Group1: 10; Group2: 20 Similarly, Regex: ??? String: 10{1,1 %d},10{2,1 %d} Expected result: Group1: 10{1,1 %d}; Group2: 10{2,1 ...
0
votes
1answer
35 views

How to match nested option values in scala

let x = new Row(job_id="hello", title=null) x match { case Row( job_id: String, title: Option[String]) => println("successful match") case _ => println("failed!"...
2
votes
2answers
62 views

How to pattern match on multiple things in a for comprehension

I have a for comprehension that has 7 things inside it. The 7 things are running DB queries in Slick and might not return any data. When they don't return any data, I want default values put it. I can ...
0
votes
0answers
21 views

or-Pattern matching in Scala [duplicate]

I have this pattern matching in scala (col, el, rbt1, rbt2) match { case (Black, z, Node(Red, y, Node(Red, x, a, b), c), d) => Node(Red, y, Node(Black, x, a, b), Node(Black, z, c, d)) case (...
0
votes
2answers
58 views

Matching string without using loop

I have 2 data sets. a <- c("adidas shoes","hot tea","pizza","hill station") b <- c("shoes","plastic cup","pizza","I love to go to hill","travelling in motor van", "buy adidas shoes","run ...
4
votes
1answer
97 views

Scala pattern-match on generics

I have a list of "string"s (a wrapper around class String, named Str), some of them with mixed traits. At some point in time I need to distinguish the mixin traits to provide additional ...
0
votes
0answers
39 views

C# pattern detection in image

Hi so i'm trying to solve following problem. I have a bitmap in which i'll set some pixels black in a certain patern. For example imagin a 5x5 gridpattern where you turn 1 pixel black on every row. ...
-1
votes
0answers
17 views

Excel match unsorted data

I have some problems to match und override some matchs. I have 2 tables and in the first column I have the ID. This id will exist or not in the second table. When the id can be found in both tables, ...
0
votes
1answer
38 views

Tail-recursive sum of elements

I am currently trying to learn about tail recursion in F# so say I have a function that takes in a list multiplies 3 to each element and then gets the sum of the list. Which the code would look ...
1
vote
1answer
62 views

How can the ref keyword be avoided when pattern matching on a newtype in a method taking &mut self?

The Rust book calls the ref keyword "legacy". As I want to follow the implicit advice to avoid ref, how can I do it in the following toy example? You can find the code also on the playground. struct ...
0
votes
1answer
26 views

Conditional Characters in Shell Globbing - Bash/Zsh

I'm trying to get a case statement to match one of four inputs in a Bash/Zsh shell: v -v version --version You can see where I'm going, right? I'm looking for this in the below case statement: ...
1
vote
1answer
66 views

Why cant I use a constant when pattern matching even though it implements PartialEq and Eq?

I want to filter out the IPv4 localhost address by using the constant net::Ipv4Addr::LOCALHOST when pattern matching: use get_if_addrs; // 0.5.3 use std::net; fn main() -> std::io::Result<()&...
1
vote
1answer
22 views

Mysql Fulltext search, natural language mode: order by “closeness”

I'm using MYSQL's FULL TEXT search functionality (in Mysql 5.6.33). If I do a MATCH in NATURAL LANGUAGE mode, for a postcode, with a one-character typo, i get some decent results back, including the ...
-2
votes
1answer
17 views

Search pattern as variable in a csv file with jmeter

I've a csv file with urls to test. Each url has a pattern which we have to test. How can I build this in my jmx file? It's a variable but how jmeter can understand that it's a variable? Thank you ...
0
votes
1answer
20 views

Pattern matching multiple cases with same action

Hello i have an abstract class with 2 derived classes.The nature of the hierarchy puts me in the undesired position where both the derived members share a common property but the superclass does not ...
1
vote
0answers
22 views

Intrusion detection using pattern matching algorithm

I am interesting in writing a simple java code for intrusion detection system(IDS). This can be a simple application for my understanding purpose. And I am gonna use pattern matching algorithm (KMP) ...
2
votes
2answers
94 views

Get number present after a particular pattern of a matching string in Python

I want to get all the matching numbers(only numbers example '0012--22') or numbers which contain some text (example 'RF332') corresponding to it which matches with a list of strings provided("my_list" ...
0
votes
1answer
36 views

How to replace particular string in table column value in PostgreSQL

I am trying to replace certain text with other text in PostgreSQL. To be more specific, I am trying to replace image path and anchor href in article (table blog_posts) from relative to absolute path. ...
1
vote
1answer
35 views

What regex can match similar characters? [duplicate]

What regex could match similar characters, like (ä and a) or in Russian (и and й)? Below my code... Sting text1 =" Passagiere noch auf ihr fehlendes Gepäck" Sting text2 =" Passagiere noch auf ihr ...
0
votes
1answer
19 views

Finding anomaly detection by pattern matching in a set of continous data

I have series of sensors (around 4k) and each sensor will measure the amplitudes at each point.Suppose I train the neural network with sufficent set of 4k values (N * 4k shape). The machine will find ...
2
votes
2answers
36 views

Elixir complex pattern matching order

I'm reading the great Joy of Elixir and I'm trying to wrap my head around the order of operations in the pattern matching example. I've got the list crew = [ %{name: "mal", age: 40}, %{...
1
vote
2answers
52 views

In Powershell -match, can $Matches be reused?

I'm attempting to read multiple values from a string. The keywords may appear anywhere in the string. I want the "Value" or content directly following it. $str ='Some version v1.2.3.4 (xyz) ...
1
vote
1answer
23 views

value matching based on common names + max value of an additional field? (R)

I'm trying to subset a dataframe for sons with a common father who have the heaviest weight. See the sample data below. va <- c("tom", "john", "regis") df1 <- data.frame(va) names(df1) <- "...
1
vote
1answer
55 views

How to match value based on time range from another table?

I have two tables as follows: table_A x | date 1 03/06 1 03/15 2 12/04 3 06/23 3 10/05 table_B x | y | start_date | end_date 1 a 03/02 03/08 1 b 03/09 03/20 1 c ...
-3
votes
2answers
73 views

Bridge and Torch Problem for 'n' people with Go [closed]

Problem: Given an array of positive distinct integer denoting the crossing time of ‘n’ people. These ‘n’ people are standing at one side of bridge. Bridge can hold at max two people at a time. When ...
0
votes
1answer
74 views

How do you sum the individual elements of a pair in a list?

Im trying to take the first and second element of the pair from a list so they can be summed. Here is my code, I am not sure why it is giving an error func :: [(Double,Double)] -> (Double,Double) ...
1
vote
2answers
39 views

Creating a column from an entry in a table

I'm having some difficulty figuring out how to take an entry in a column event_name where match_id = 1 and applying that entry to every record in a new column partitioned by visit_id and pattern_id ...
0
votes
1answer
15 views

SpaCy: Match part of Doc

I tried to use SpaCy's Matcher to search a span, but it turns out I can't. Argument 'doc' has incorrect type (expected spacy.tokens.doc.Doc, got spacy.tokens.span.Span) How can I search only a part ...
0
votes
0answers
21 views

How to find the dynamic pattern in a group of number in Python?

In the previous post finding patterns within a large group of number gives an idea of how to find specific number pattern in on list or array. In which a specific pattern is used. In my this post, I ...
0
votes
2answers
36 views

Is there a less verbose way to unwrap a type with only a single tag?

Is there a less verbose way to unwrap a type with only a single tag, e.g. currently I do case myObject of TheTag arg -> foo but I'm thinking that the compiler should be smart enough to know that ...
1
vote
1answer
55 views

R: Count appereances of vector y in x

Suppose you have two vectors y and x with length(y) < length(x). What I want is to count how often all elements of y appear in x in the same order. I can assume that the elements of y appear at ...
-1
votes
1answer
29 views

compile method special characters java [duplicate]

Using the pattern matcher method, how do I include whitespace in my list of characters? This and other methods I'd used so far won't work. `if(Inputpassword.length() >= 8) { ...
0
votes
2answers
116 views

Could pattern-matching in do-notation/enumFromTo slow down a Haskell code?

I've been solving a pretty easy problem: generation of all decreasing sequences in length of L, consisting of natural numbers from 1 up to M in lexicographical order. Yet, I ran into a quite strange ...
0
votes
0answers
19 views

Meaning of match pattern in web extension manifest.json file

What does this match pattern declaration in manifest.json file imply ? I read from the following URL and can't find any results. https://developer.chrome.com/extensions/declare_permissions https://...
0
votes
2answers
45 views

Xcopy directory pattern matching

I need to copy source file to destination folder using bat file. I have created this: @echo off set source="D:\Folder1\file.dll" set destination="D:\Test\TestCopy*\Test\" xcopy /s /y %source% %...
4
votes
4answers
51 views

Python capture a specific pattern inside a string with regular expressions

I have a string like this '6\' 3" ( 190 cm )' and I would like to extract '190 cm' only using regular expressions. I can't find the appropriate pattern to look for. I have tried string ='6\' 3" ( ...
0
votes
1answer
29 views

Issue identifying pattern with vertica match clause

I'm having some difficulty understanding how to leverage Vertica's match clause to identify sessions in which a user searched for something on our site (event_category ='Search') and then saw a ...
-2
votes
1answer
24 views

Mapping logic for converting a pattern in excel or database

I have thousands of mapping pattern that I need to convert. Attached is the image which shows the source value which I need to convert into Target values. Few of the rules that I am able to decipher ...

http://mssss.yulina-kosm.ru