7,772 questions
Advice
0
votes
3
replies
67
views
String manipulation: extract words under brackets
I'm not yet very familiar with the patterns in Lua's string.gsub function.
If I have a string like this:
Fishing Lure(+100 Fishing Skill)(1 hour)
and I want extract only the string "1 hour"...
0
votes
1
answer
142
views
how to avoid "borrow of moved value" with subpattern match
Edit: added a second part of the question below.
I am getting the error "borrow of moved value" here, but the thing being moved is an &mut Containee, so I didn't expect it to cause a ...
9
votes
1
answer
152
views
Primitive types in patterns: why doesn't Integer dominate byte?
JEP 455 introduced Primitive Types in Patterns, instanceof, and switch as a preview feature in JDK 23. It continues as a preview feature in JDK 24 and 25, so the feature is not detailed in the Java ...
2
votes
1
answer
69
views
Postgres not using index with varchar_pattern_ops for pattern matching query
I have a query in PostgresSQL accessing a big table using a LIKE clause for pattern matching:
Table "rmx_service_schema.document"
...
1
vote
1
answer
142
views
Pattern matching in GridDB using NewSQL
I am looking for pattern matching in GridDB using NewSQL to return values true when matched and false when not matched.
The string can start with
91 followed 33 followed by 8 digit number followed by ...
0
votes
1
answer
85
views
Transform a match to avoid duplicate
Is there a construct which allows to drop the repetition of the 0.0 routine below
val price: Option[Double] = ???
price match {
case Some(d) =>
if (isPriceFair(d))
d
else
...
1
vote
1
answer
113
views
Avoiding redundant else
class Person( id:String , age:Option[Double])
val rows: Seq[Person] = List(Person("a",None),Person("c",None),Person("e",50))
val ages = rows.foreach( r => r.age ...
-2
votes
1
answer
106
views
R: Partial matching values in a vector with partial match in df [duplicate]
I am trying to do some inventory management, I have a list of catalog numbers of materials we need and a list of managed stock onsite. I have a vector of catalog numbers (num) which are accurate to ...
1
vote
1
answer
122
views
Using pattern matching with a class that inherits from str in Python 3.10
In a parser library I maintain, I have some classes that inherit from str to manage parsed strings and parsed symbols. This has been working well for a long time, but with Python 3.10, someone ...
1
vote
1
answer
63
views
SML pattern matching on datatypes with constructors from function arguments
In the example, there is a "match redundant" Error, indicating that SOME s is matching on every string and not the provided s:
fun matchs (s : string) : (string option -> bool) =
fn x =&...
3
votes
6
answers
158
views
how to select matching rows in multiple files with AWK
I have over forty files with the following structure:
file1 first 21 lines
8191 M0
139559 M1
79 M10
1 M10007
1 M1006
1 M10123
file2 first 21 lines
8584 M0
119837 M1
72 M10
1 M10003
1 M10045
1 M1014
...
0
votes
0
answers
43
views
I can't understand variable @ subpattern in Rust [duplicate]
There is an example in the official book:
let x = 2;
match x {
e @ 1 ..= 5 => println!("got a range element {}", e),
_ => println!("anything"),
}
What's the point ...
2
votes
0
answers
110
views
Pattern matching, LIKE and wildcards
I am using Microsoft® Excel® 2019 MSO (バージョン 2504 ビルド 16.0.18730.20122) 32 ビット
and made MACRO as under
If Range(HotelCol & Row).Value Like "*" & HTLArray(HtlRmNtRow) & "*&...
3
votes
2
answers
131
views
Pattern matching for null values "AssignableTo" type?
Given a list of objects to be passed to a method with overloads, I want to determine what overload best matches the object types in order to invoke that method.
string TheMethod(string? foo, string? ...
4
votes
1
answer
201
views
Efficiently searching for a 3D pattern in a infinite array
I have access to a function bool getState(int x, int y, int z) that returns the value of a infinite 3D boolean array, conceptually shaped as [∞][4][∞]. That is, the Y dimension is limited to 4, but X ...
0
votes
2
answers
137
views
Extract StringValues first or only string with C# pattern matching
If I have a StringValues, with following possible values:
"AString"
["OnlyString"]
["FirstString", "IDontCare"]
How can I use C# pattern matching to extract a ...
4
votes
0
answers
58
views
Why does pattern matching match Int16[] to UInt16[] in c#? [duplicate]
Why is it that if I switch on an Int16[] in C#, it will match with UInt16[], even when an Int16[] is present later in the switch statement?
Example Code:
namespace SwitchError;
internal class Program
...
0
votes
1
answer
101
views
Swift pattern matching error using region [closed]
I am using SWiftui and Xcode 16.2 and I am trying to get a region but getting this error . I have been searching around to see how I can resolve this but no luck
'let' binding pattern cannot appear in ...
0
votes
1
answer
79
views
Is there a way to name a subexpression of a match pattern?
Is there a way to label a subexpression of a pattern so that the name can be reused? Consider:
fn parse(all_toks : Vec<Token>) -> ParseResult<Form> {
match all_toks {
[
...
0
votes
2
answers
116
views
How to use pattern matching with objects?
I have the following python code that converts an object into a view-like mapping.
from collections.abc import Mapping
class ObjView(Mapping):
def __init__(self, obj):
self.obj = obj
...
0
votes
1
answer
55
views
Can I name part of a pattern in Racket's match?
Let's say I have this part of a pattern match:
(define/match (make lst)
[((list)) (const #f '())]
[((list (cons _ n))) (cons (make-tree-node n) '())]
[((list-rest (cons parent pnum) (cons child ...
2
votes
1
answer
160
views
Index for ILIKE + unaccent()
I have a lot of queries using
...
WHERE company_id = 2
AND unaccent(name) ILIKE unaccent('value');
Is possible to create a index to optimize this type of query? I take a look at GIN and pg_trgm but ...
0
votes
1
answer
58
views
GNU guile pattern matching: quasi-quote "ooo" quantifier pattern not work
I encountered some errors with pattern matching.
For quasi-quote, the "ooo" pattern including "..." does not work. I looked at source code "guile-3.0.10/module/ice-9/match....
-1
votes
1
answer
143
views
How can I match a superclass and all its subclasses in a Java switch statement without explicitly listing each subclass?
Wrt to Java pattern matching (JEP 441), if I am matching an object using a switch statement, like this:
switch (cases) {
case A(
B b,
C c,
D d,
) -> doSomething();
}
...
0
votes
1
answer
111
views
What is the difference between these patterns?
The pattern [] only matches empty lists, while [_] only matches lists with exactly one element ([_,_] for exactly two elements and so on).
So far it is logical for me.
But it seems the patterns [..] ...
2
votes
1
answer
102
views
Use pattern matching to split array into sub-arrays
I have a Rust [i32; 6] that I'd like to split into three [i32; 2]. Can this be done by pattern matching, or do I explicitly have to reference all six elements?
I'd like to do something like this:
let ...
7
votes
1
answer
149
views
Does switch support objects other than Byte, Short, Character, Integer, enumerated types, and the String type?
JDK 7 added support for String with a switch, which extended the list of types supported by switch. As of Java 7, a switch supported the primitive types byte, short, char, and int, their respective ...
0
votes
1
answer
69
views
Struct update syntax equivalent for enum variants
Can we use fields of a pattern-matched enum variant to fill the fields of another variable of the same type? In other words, is it possible to make the following code work?
#[derive(Debug)]
enum Enum {...
3
votes
4
answers
124
views
Count how often words from a vector occur in a string
I have a string of text and a vector of words:
String: "Auch ein blindes Huhn findet einmal ein Korn."
Vector: "auch", "ein"
I want to check how often each word in the ...
0
votes
1
answer
62
views
What's the proper way to disallow digits in a pattern in html?
I have this pattern [a-z0-9.+-_%]+@[a-z.-]+\.[a-z]{2,}$ that's supposed to only allow letters a-z. and - in the domain name of an email (after @ and before .), but inputting [email protected] is ...
5
votes
1
answer
161
views
Using Recursive Regexes in Raku: how to limit recursion-levels?
Raku has an interesting and exciting recursive-regex notation: <~~>.
So in the REPL, we can do this:
[0] > 'hellohelloworldworld' ~~ m/ helloworld /;
「helloworld」
[1] > '...
1
vote
1
answer
85
views
Why does range() in Python require positional arguments when called, but keyword arguments in a match statement?
All examples tested using Python 3.13.2 on Windows 10.
When calling range(), I must use positional arguments, or otherwise I get an exception.
>>> range(2, 5)
range(2, 5)
>>> range(...
2
votes
0
answers
88
views
Find Substrings In A Dynamic Collection Of String
This question is a little complicated, so I try to describe it through an example.
First, we get a string foo, and put it into collection S.
Then we get a string sample, and put it into S too.
Next, ...
1
vote
1
answer
71
views
Match similar names [duplicate]
I have a database with three columns: name, occupation, and organization. In these columns, I have duplicates with slightly different names. For example, Anne Sue Frank and Anne S. Frank refer to the ...
0
votes
0
answers
30
views
How to Dynamically Parse Nested Configurations Without Explicit Recursion in Python using Match?
I’m exploring the new match statement introduced in Python 3.10. I want to learn how to parse JSON strings or YAML.
Here’s the specific problem:
The configuration structure can vary significantly ...
5
votes
2
answers
423
views
A more efficient way to check which substrings are present in several test strings?
I would like to write an R function that takes a string as input, checks if several thousand substrings are present in that string, and returns a vector of substrings found in the tested string.
I ...
0
votes
0
answers
40
views
Accidentally created a infinite loop while trying Match Case
I did an oopsie and made an infinite loop at the match case in the end:
import pyautogui
import cv2
import numpy as np
import time
def find_image(image_path, confidence=0.8):
screenshot = ...
2
votes
1
answer
77
views
Using sympy.replace and Wild symbols to match and substitute arbitrary functions
Is it possible with sympy Wild symbols and replace to match arbitrary function applications?
What I would ideally like to do is the following:
x = Symbol('x')
expr1 = sin(x)
expr2 = exp(x)
F = Wild('F'...
1
vote
1
answer
113
views
Why does this code parse a null string instead of a None?
I'm looking to parse a string that can be in one of the following formats:
"[a]"
"[a-b]"
"[a-b/9]"
"[a-b, b-c]"
"[a-b/9, b-c]"
In words, the part ...
0
votes
3
answers
92
views
How could we use a value instead of a name/identifier in let expression?
I saw below code:
let () = assert (f input1 = output1)
The assert expression returns a value of type unit, which has only one possible value displayed as ().
My understanding is, the let definition ...
-1
votes
1
answer
50
views
Sed opening and closing parentheses contents [closed]
How to read numbers between pattern?
Input string:
([\\S\\s]{8}))([\\S\\s]{20}))([\\S\\s]{10}))
Output should be:
8
20
10
Note: opening and closed parenthesis are not fixed but it will be in pairs.
0
votes
1
answer
166
views
LEAN 4: Apparent Contradiction re Arguments that may be referenced by 'match'
In Hitchiker's Guide to Logical Verification (2023 Standard Edition) Ch. 2, p. 16, we have this --
"The general format of recursive definitions is:
def name (params1 : type1) . . . (params-m :...
1
vote
1
answer
81
views
An algorithm to match associative and commutative patterns
Background
For simplicity, just using ADD as an example.
In compiler backend, multiple addition is organized by combinations of multiple ADD instructions. For example ADD(1, ADD(1,3)).
But since it is ...
0
votes
0
answers
46
views
Optimizing Perlin Noise Matching for Binary Image Comparison: Slow Processing and Low SSIM Score
I’m working on a project where I need to generate Perlin noise and match it with a binary (black & white) image. I want to find the Perlin noise pattern that best matches the input image in terms ...
0
votes
1
answer
154
views
In Rust can I filter lines of a String that contain codes like "1.2.3" OR "1.2.3.4"?
I am building a program to help count the number of distinct codes that occur in multiple PDFs. I have got the data from the PDFs, that's not a problem. I just need to filter the lines based on ...
1
vote
1
answer
66
views
Haskell pattern matching on a list of lists - why doesn't this work? [duplicate]
I have the following definitions in my Haskell code:
-- A region has a list of squares, and a list of possible combinations of values,
-- all of which add up to the same total.
data Region = Region [...
0
votes
1
answer
97
views
Rust idomatic way to decrementing the value from a map and remove the key when value is 0
Noob to Rust and trying to figure out the idomatic way to decrement the value from a hashmap and remove the corresponding key when the value after decrementing reaches 0.
I am doing it like this but ...
1
vote
2
answers
84
views
Matching enum variant without specifying variants in Rust macro
I am trying to use enum variants to store variables specific to tabs in an app. I am using the below code to extract the variable out of the enum. (because accessing a variant directly doesn't work, ...
7
votes
1
answer
240
views
Why do I need an apparently useless type annotation when a closure matches against an enum-with-lifetime argument?
Here's a minimal reproduction for an issue I was having in a larger codebase:
enum A<'b> {
A1(&'b u8)
}
fn consume_fnmut(_f: &mut impl FnMut (A)) {}
// Desugared:
// fn ...
3
votes
1
answer
151
views
Why does a | (pipe) in a rust pattern match cause a "value used after move"?
EDIT: this question is based on a faulty premise. Turns out that this was a false-positive from my IDE; the code is perfectly valid. See answer below.
In rust, I'm a little confused about the ...