我有一个姓氏和名字同时出现的名字列表:
BorisovaSvetlana A.; KimHak Joong; PuXiaotao; LiuHung-wen*
Run Code Online (Sandbox Code Playgroud)
我想在姓和名之间添加一个逗号和空格,以使输出为:
Borisova, Svetlana A.; Kim, Hak Joong; Pu, Xiaotao; Liu, Hung-wen*
Run Code Online (Sandbox Code Playgroud)
我在KNIME中使用一个String Manipulation节点,并且我想regexReplace($col1$, ,"")会使用它,也许使用[az]和[AZ]进行某种先行查找以直接在大写字母后写一个小写字母,但是我对regex不熟悉到目前为止,这就是我所拥有的。
我该如何解决这个问题?
我想将一段perl代码转换为python,但我对perl及其语法一点都不熟悉。
特别是,我对perl中的map运算符和下面的代码中的shift运算符感到困惑。
(@M) = ($y =~ m/((?:\d+:ITEM7 \d+:\d+ )+(?:\d+:ITEM7A \d+:\d+ )*)(?:\d+:ITEM8 \d+:\d+\s*)+/g);
$best = 0;
$bestseq = "";
for($i = 0; $i < scalar(@M); ++$i) {
$m = $M[$i];
$m =~ s/\d+://g;
(@m) = (split / /, $m);
$v = 0;
$z = length_in_words($M[$i]);
map { $v += $_ if($_ =~ m/^\d+$/); } @m;
if($v > $best) { $best = $v; $bestseq = $M[$i]; }
}
sub length_in_words {
my $x = shift;
my @k;
return scalar(@k = $x =~ …Run Code Online (Sandbox Code Playgroud) 如何确保我不会重复得到随机数?目前,这不起作用。我正在使用本地数组来存储以前的结果。
getUniqueRandomNumber(x){
var index;
var viewedIndices = [];
index = Math.floor(Math.random() * (x));
if(viewedIndices.includes(index))
{
viewedIndices.push(index);
this.getUniqueRandomNumber(x);
}
else {
console.log(index);
return index;
}
}
Run Code Online (Sandbox Code Playgroud) 在javascript中,我使用下一个代码来剥离linefeeed和字符串的回车符,并且效果很好:
var values="something....."
var sanit=values.replace(/(\r?\n|\r\n?)/g, "");
Run Code Online (Sandbox Code Playgroud)
在Delphi中,我正在尝试下一个代码:
values="something....."
sanit:=TRegex.Replace(values,'/(\r?\n|\r\n?)/g', '');
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。没有替换完成。
我正在尝试创建一个具有定义长度的数组,并用空数组填充它。我已经尝试过使用@stpoa的答案在此处给出的所有可能性,但是我的数组无法正常运行。
给定代码(为示例起见,我对其进行了简化):
const tasksArray = Array(3).fill([])
const tasksArray2 = [[], [], []]
const tasks = ['task1', 'task2']
const fillWithData = (array) => {
tasks.forEach(task => {
array[0].push(task)
})
}
Run Code Online (Sandbox Code Playgroud)
给我一个不正确的输出,tasksArray显然给一个正确的tasksArray2硬编码输出
fillWithData(tasksArray) // [['task1', 'task2'], ['task1', 'task2'], ['task1', 'task2']] => not OK, duplicates values!
fillWithData(tasksArray2) // [['task1', 'task2'], [], []] => that's OK
Run Code Online (Sandbox Code Playgroud) 在C#中,是否有任何语法糖可以在单个语句中执行以下操作(基本上是有条件的返回):
public SomeBaseType MyFunction()
{
// Can the two statements below be combined into one?
SomeBaseType something = SomeFunction();
if ( something != null ) { return something; }
// End of statements regarding this question.
// Do lots of other statements...
return somethingElseThatIsADerivedTypeThatDoesntMatter;
}
Run Code Online (Sandbox Code Playgroud) 我想验证一个字符串,当点“。”时正则表达式不匹配。之前或之后直接有“-”或“ _”。
我认为负面的前瞻是最好的方法,但我似乎无法正确地做到这一点。
我正在开发一个需要vim在任意行和任意列中打开文件的模块。我正在通过进行操作exec(),但vim没有获得正确的行和列:
如果我将其简化为单线:
perl -E "exec(q{vim}, q{+'call cursor(1,3)'}, q{README.md})"
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
"README.md" 116L, 3790C
Error detected while processing command line:
E20: Mark not set
Press ENTER or type command to continue
Run Code Online (Sandbox Code Playgroud)
当vim显示此错误时,ps显示vim +'call cursor(1,3)' README.md,这是我想要的命令。实际上,复制/粘贴vim +'call cursor(1,3)' README.md到新的终端窗口中可以使我获得所需的行为。
在我看来,vim当通过Perl的命令运行命令时,该行是116,而不是1,该列是3790,而不是3 exec()。
这是Perl 5.26.1,Vim 8.1和GNU bash版本3.2.57(1)-发行版(x86_64-apple-darwin18)。
给定一个仅由数字、逗号和点组成的字符串。你的任务是完成regex_pattern下面的定义,它将用于re.split()所有的,和.符号。保证每个逗号和每个点的前面和后面都有一个数字。
Sample Input 0
100,000,000.000
Sample Output 0
Run Code Online (Sandbox Code Playgroud)
我正在使用 Python 3.7.2,我尝试re.split使用\,*and ,\.*如下代码所示,但它似乎在每个数字之后打印。
regex_pattern = r"\,*\.*"
import re
print("\n".join(re.split(regex_pattern, input())))
Run Code Online (Sandbox Code Playgroud)
然而,这似乎是以错误的顺序打印的。
我应该添加什么regex_pattern?
预期结果是:
regex_pattern = r"\,*\.*"
import re
print("\n".join(re.split(regex_pattern, input())))
Run Code Online (Sandbox Code Playgroud)
但是,我得到:
100
000
000
000
Run Code Online (Sandbox Code Playgroud) 我想要的是,生成一个显示在ah标签中的随机值,并在另一个标签中显示相对于该随机值的好值。
var first = ['1+2', '10+20', '100+200'];
var second = ['3', '30', '300'];
var first_value = first[Math.floor(Math.random()*first.length)];
var second_value = second[Math.floor(Math.random()*second.length)];
document.getElementById('first_value').innerHTML = first_value;
document.getElementById('second_value').innerHTML = second_value;
Run Code Online (Sandbox Code Playgroud)
目前,所有内容都是随机生成的,生成的2个值之间没有关系。
如果随机选择“ 10 + 20”,我想在第二个html标签中显示“ 30”。
regex ×5
javascript ×3
arrays ×2
perl ×2
python ×2
random ×2
string ×2
bash ×1
c# ×1
delphi ×1
ecmascript-6 ×1
exec ×1
if-statement ×1
knime ×1
numbers ×1
powershell ×1
regex-greedy ×1
regex-group ×1
replace ×1
split ×1
vim ×1