Good morning all,
I want to make a regex that match 3 same consecutive numbers. It should match only 3 numbers in a row (separated by a space), the numbers should be identical. If there are less or more than 3 same numbers, then the output should be false
I have tried this regex /.*(\d+) \1 \1(?!(\s\1))/
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 4 hey yoo')); //false --> Correct
console.log(/.*(\d+) \1 \1(?!(\s\1))/.test('I am 42 42 42 hey yoo')); //true --> …Run Code Online (Sandbox Code Playgroud) 给出以下示例:
from dataclasses import dataclass
@dataclass
class Person:
name: str = ""
@dataclass(kw_only=True)
class AnotherPerson:
name: str = ""
print(Person.__match_args__)
print(AnotherPerson.__match_args__)
Run Code Online (Sandbox Code Playgroud)
运行时,您会得到以下信息:
('name',)
()
Run Code Online (Sandbox Code Playgroud)
根据dataclass match_args参数的文档(重点是我的):
match_args:如果为 true(默认为 True),将从生成的 __init__() 方法的参数列表中创建 __match_args__ 元组(即使未生成 __init__(),请参见上文)。如果为 false,或者类中已定义 __match_args__,则不会生成 __match_args__。
鉴于match_args默认值为 true,我认为__match_args__变量应该设置为方法中出现的值__init__,尽管关键字参数的情况似乎并非如此。这只是一个未记录的限制,还是我做错了什么?
__match_args__无论如何,我将如何在不明确写出这些元组的情况下生成它们?
python python-dataclasses python-3.10 structural-pattern-matching
此代码适用于所有其他浏览器,但在 Safari 浏览器上右侧空间不对称,但在其他浏览器上一切正常。我知道 Safari 不支持此属性,我正在寻找解决方案。
.card {
background: red;
padding: 24px 12px 24px 24px;
width: 240px;
margin: 0 auto;
height: 160px;
}
.scrollable-content {
scrollbar-gutter: stable;
overflow-y: auto;
scrollbar-width: thin;
}
.scrollable-content::-webkit-scrollbar {
width: 12px;
background-color: blue;
}
.scrollable-content::-webkit-scrollbar-track {
border-radius: 8px;
}
.scrollable-content::-webkit-scrollbar-thumb {
background-clip: content-box;
background-color: rgba(136, 136, 136, 0.5);
border: 4px solid transparent;
border-radius: 8px;
height: 56px;
}
.scrollable-content::-webkit-scrollbar-thumb:hover {
background-color: #888888;
}
.card-body {
background-color: yellow;
}Run Code Online (Sandbox Code Playgroud)
<div class="card scrollable-content">
<div class="card-body">
test lorem100
</div>
</div> …Run Code Online (Sandbox Code Playgroud)我开始探索 mojo 编程语言,现在我正在尝试弄清楚如何正确使用 Tensor 模块。我找不到如何静态声明张量内的值。
目前,我用值填充张量:
let dim1 = 2
let dim2 = 3
var matrice1 = Tensor[DType.float32](dim1, dim2)
for i in range(dim1):
for j in range(dim2):
matrice1[Index(i,j)] = 1
Run Code Online (Sandbox Code Playgroud)
但我正在寻找一种方法来做这样的事情:
var matrice1 = Tensor[DType.float32](dim1, dim2)
matrice1 = [[1, 2, 3],[1, 2, 3]]
Run Code Online (Sandbox Code Playgroud) 我有一些像这样的html:
var html = '<h1>heading</h1><p>Lorem ipsum dolor sit amet<br>more text</p><ul><<li>Bulleted text</li></ul>'
Run Code Online (Sandbox Code Playgroud)
我想将此字符串转换为谷歌文档中的富文本。我有什么办法可以做到这一点吗?
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j += i) {
// some code
}
}
Run Code Online (Sandbox Code Playgroud)
外循环肯定会运行n多次。对于内循环,假设 n = 8,
| 我 | j |
|---|---|
| 1 | 1, 2, 3, 4, 5, 6, 7, 8 ---> 跑了N次 |
| 2 | 1, 3, 5, 7 ---> 运行 N/2 次 |
| 3 | 1, 4, 7 |
| 4 | 1, 5 |
| 5 | 1, 6 |
| 6 | 1, 7 |
| 7 | 1, 8 |
| 8 | 1 |
我很困惑复杂性应该是复杂性logn还是n内部循环。任何帮助将不胜感激!
我试图匹配以某个字符串开头的整个字符串,然后匹配任意数量的字符::,除非::匹配,否则仅接受 if 后跟该字符串CASE。
例如:以 开头,后跟Linus::0 个或多个 1 字符的字符串,除非 if ::thenCASE必须跟在 else 后面,仅匹配 之前的所有内容::。
Linus::AOPKNS::CASE将捕获整个字符串
Linus::AOPKNS将捕获整个字符串
Linus::AOPKNS::OK只会捕获Linus::AOPKNS
我想我必须使用积极的前瞻,但考虑到我想匹配 之前的任意数量的字符,我不太确定该怎么做::。
我正在尝试匹配仅包含字母数字组合的 6 个字符单词。
示例字符串:
Bus Express Wash at bay no 083457 - Truckno AB96CD & Truck no 12367S & 12368S
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试正则表达式[a-zA-Z0-9]{6}
但是,它匹配以下输出:
xpress
083457
ruckno
AB96CD
12367S
12368S
Run Code Online (Sandbox Code Playgroud)
但是,我需要的只是字母数字的组合。类似于下面的期望输出
AB96CD
12367S
12368S
Run Code Online (Sandbox Code Playgroud) 我绝不是一名程序员,但我有一个想法。我使用 webflow 工具创建网站,当您设置带有富文本字段的 CMS 集合时,客户端可以添加包括 h1 在内的标题,但我不希望它们这样做。我的想法是,使用 javascript 将类中的每个 h1 替换为 h2 (这样页面标题就不会改变)。
到目前为止,我设法创建了这个:
var e = document.getElementsByTagName('h1')[0];
var d = document.createElement('h2');
d.innerHTML = e.innerHTML;
e.parentNode.replaceChild(d, e);Run Code Online (Sandbox Code Playgroud)
<h1>Don't change this</h1>
<div class="the-class">
<h1>Replace this with h2</h1>
</div>Run Code Online (Sandbox Code Playgroud)
我有一个text,我需要匹配除给定单词之外的所有文本部分regexp
例如,如果文本是' Something went wrong and I could not do anything '并且给定的单词是'and','not'那么结果必须是['Something went wrong', 'I could', 'do anything']
请不要建议我使用string.split()orstring.replace()等。我知道有几种方法可以使用内置方法来做到这一点。我想知道是否有一个正则表达式可以做到这一点,当我执行时text.match(/regexp/g)
请注意,正则表达式必须至少在不低于当前一比三的 Chrome、Firefox 和 Safari 版本中工作!在提出这个问题时,实际版本分别是 100.0、98.0.2 和 15.3。例如,您不能在 Safari 中使用Lookbehind功能
请在回答我的问题之前,访问https://regexr.com/并检查您的答案!您的正则表达式应突出显示句子的所有部分,包括需要部分的单词之间的空格以及需要部分周围的空格(给定的单词除外)
在问这个问题之前,我尝试自己进行搜索,但此链接对我没有帮助。我还尝试了不被接受的答案:
javascript ×4
regex ×4
html ×3
python ×2
algorithm ×1
big-o ×1
c# ×1
css ×1
google-docs ×1
java ×1
match ×1
mojolang ×1
python-3.10 ×1
string ×1
structural-pattern-matching ×1
tensor ×1
web ×1