我有一个jq问题。给定文件file.json包含:
[
{
"type": "A",
"name": "name 1",
"url": "http://domain.com/path/to/filenameA.zip"
},
{
"type": "B",
"name": "name 2",
"url": "http://domain.com/otherpath/to/filenameB.zip"
},
{
"type": "C",
"name": "name 3",
"url": "http://otherdomain.com/otherpath/to/filenameB.zip"
}
]
Run Code Online (Sandbox Code Playgroud)
我正在寻找使用jq创建另一个文件,仅当 url 的值与某个模式匹配时才修改 url。例如,我想更新任何与模式匹配的网址:
http://otherdomain.com.*filenameB.*
Run Code Online (Sandbox Code Playgroud)
到一些固定的字符串,例如:
http://yetanotherdomain.com/new/path/to/filenameC.tar.gz
Run Code Online (Sandbox Code Playgroud)
生成的json:
[
{
"type": "A",
"name": "name 1",
"url": "http://domain.com/path/to/filenameA.zip"
},
{
"type": "B",
"name": "name 2",
"url": "http://domain.com/otherpath/to/filenameB.zip"
},
{
"type": "C",
"name": "name 3",
"url": "http://yetanotherdomain.com/new/path/to/filenameB.tar.gz"
}
]
Run Code Online (Sandbox Code Playgroud)
我什至无法找到网址,更不用说更新它了。这是我得到的(错误的结果,并不能帮助我解决更新问题):
% cat file.json | jq -r …Run Code Online (Sandbox Code Playgroud) 所以我有一个字符串列表如下:
list = ["I love cat", "I love dog", "I love fish", "I hate banana", "I hate apple", "I hate orange"]
Run Code Online (Sandbox Code Playgroud)
如何在没有给定关键字的情况下遍历列表并对部分匹配的字符串进行分组。结果应如下所示:
list 1 = [["I love cat","I love dog","I love fish"],["I hate banana","I hate apple","I hate orange"]]
Run Code Online (Sandbox Code Playgroud)
非常感谢。
我有一个字符串
"我的名字是安德鲁,我非常棒".
让我们说我有一个列表,如
[['andrew','name','awesome'],['andrew','names','awesome']]
我需要我的解决方案才能回归
['andrew','name','awesome']
天真的解决方案是:
myString='My name is Andrew, I am pretty awesome'
keywords = [['andrew', 'name', 'awesome'], ['andrew', 'designation', 'awesome']]
results=[]
for i in keywords:
if all(substring in myString.lower() for substring in i):
results.append(i)
print results
Run Code Online (Sandbox Code Playgroud)
我的问题是,当列表关键字非常大(比如100000)时,存在性能瓶颈.我需要知道最有效的方法.
第一次发帖,如果我的格式不正确,请提前道歉。
这是我的问题:
我创建了一个包含多行文本的 Pandas 数据框:
d = {'keywords' :['cheap shoes', 'luxury shoes', 'cheap hiking shoes']}
keywords = pd.DataFrame(d,columns=['keywords'])
In [7]: keywords
Out[7]:
keywords
0 cheap shoes
1 luxury shoes
2 cheap hiking shoes
Run Code Online (Sandbox Code Playgroud)
现在我有一个包含以下键/值的字典:
labels = {'cheap' : 'budget', 'luxury' : 'expensive', 'hiking' : 'sport'}
Run Code Online (Sandbox Code Playgroud)
我想做的是找出数据框中是否存在字典中的键,如果存在,则返回适当的值
我能够使用以下方法到达那里:
for k,v in labels.items():
keywords['Labels'] = np.where(keywords['keywords'].str.contains(k),v,'No Match')
Run Code Online (Sandbox Code Playgroud)
但是,输出缺少前两个键并且只捕获最后一个“远足”键
keywords Labels
0 cheap shoes No Match
1 luxury shoes No Match
2 cheap hiking shoes sport
Run Code Online (Sandbox Code Playgroud)
此外,我还想知道是否有办法在以 | 分隔的字典中捕获多个值。,所以理想的输出看起来像这样
keywords Labels
0 cheap …Run Code Online (Sandbox Code Playgroud) 编号 | 名称 | IP地址
---+----------+-------------------------
1 | 测试名称 | {192.168.1.60,192.168.1.65}
我想ipAddress用 进行搜索LIKE。我试过:
{'$mac_ip_addresses.ip_address$': { [OP.contains]: [searchItem]}},
Run Code Online (Sandbox Code Playgroud)
这也:
{'$mac_ip_addresses.ip_address$': { [OP.Like] : { [OP.any]: [searchItem]}}},
Run Code Online (Sandbox Code Playgroud)
的数据类型ipAddress是text[]. 我想用 进行ipAddress搜索LIKE。
searchItem包含需要在ipAddress字段中搜索的 IP,因此我想在数组中搜索LIKE.
arrays postgresql database-design string-matching sequelize.js
我正在尝试在注册用户时处理我的 android 应用程序中的错误情况。我想确保提供的电子邮件地址是有效的,有效是指正确的格式:“something@something.com”。
我在 google 和 stackoverflow 上搜索过,但在 Kotlin 中找不到确切的答案。
我有一个看起来像这样的主字符串:
my_main <- "ABCDEFGHIJ"
Run Code Online (Sandbox Code Playgroud)
我想要做的是用另一个模式字符串在每个位置顺序屏蔽:
my_pattern <- "x*x" # the length could be varied from 1 up to length of my_main
Run Code Online (Sandbox Code Playgroud)
与 重叠的每个字符都*将被保留,其他字符将被替换为x。
最终结果是包含以下内容的字符串向量:
xBxDEFGHIJ
AxCxEFGHIJ
ABxDxFGHIJ
ABCxExGHIJ
ABCDxFxHIJ
ABCDExGxIJ
ABCDEFxHxJ
ABCDEFGxIx
Run Code Online (Sandbox Code Playgroud)
接下来如果模式是
my_pattern <- "xx**x"
Run Code Online (Sandbox Code Playgroud)
结果将是:
xxCDxFGHIJ
AxxDExGHIJ
ABxxEFxHIJ
ABCxxFGxIJ
ABCDxxGHxJ
ABCDExxHIx
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个像这样的字符串:
a b c d
Run Code Online (Sandbox Code Playgroud)
我像这样处理我的字符串:
chomp $line;
my @tokens = split /\s+/, $line;
my @new_tokens;
foreach my $token (@tokens) {
push @new_tokens, some_complex_function( $token );
}
my $new_str = join ' ', @tokens;
Run Code Online (Sandbox Code Playgroud)
我想重新加入原始空格的字符串.有什么方法可以存储分割的空白并在以后重新使用它?或者这会是一个巨大的痛苦?它主要是装饰性的,但我想保留输入字符串中的原始空格.
我在wordpres中使用帖子GUID构建了一个导航菜单,并且发布标题,我只占用了标题的一部分并且这样做我正在执行以下操作,
$casestudylist .= "<li class='subnav'><a href=".$v->guid.">". strstr($v->post_title, ":", true)."</a></li>";
Run Code Online (Sandbox Code Playgroud)
但是我收到以下警告并且无法解决原因:
wrong parameter count for strstr()
Run Code Online (Sandbox Code Playgroud)
基本上我试图从字符串中拉出所有字符,如果它们在a之前:.
有许多字符串匹配算法可用于在大文本中查找模式(字符串),如Boyer-Moore,Aho-Corasick等.
std::search在C++中应用哪种字符串匹配算法来实现函数?
string-matching ×10
string ×4
python ×3
regex ×3
algorithm ×1
arrays ×1
c++ ×1
dictionary ×1
fuzzy-search ×1
grouping ×1
jq ×1
json ×1
kotlin ×1
pandas ×1
perl ×1
php ×1
postgresql ×1
python-3.x ×1
r ×1
search ×1
sequelize.js ×1
strstr ×1
url ×1