标签: repeat

获取字符串中重复的字符

我尝试匹配/获取字符串中的所有重复项。这是我到目前为止所做的:

var str = 'abcabc123123';
var REPEATED_CHARS_REGEX = /(.).*\1/gi;

console.log( str.match(REPEATED_CHARS_REGEX) ); // => ['abca', '1231']
Run Code Online (Sandbox Code Playgroud)

如您所见,匹配结果为['abca', '1231'],但我希望得到['abc', '123']. 有什么想法可以实现吗?

第二个问题:

我期望的另一件事是可以更改字符需要在字符串中多久才能匹配的持续时间...

例如,如果字符串是abcabcabc并且重复时间设置为2它应该导致['abcabc']. 如果设置为3它应该是['abc'].

更新

一个非RegExp解决方案是完全可以的!

javascript regex string character repeat

0
推荐指数
1
解决办法
6492
查看次数

重复数组中的值直到特定长度

我需要某种功能或小技巧来解决我的问题。

所以我得到了一个列表, [1,2,3,4] 但我需要这个数组更长,重复相同的元素,所以假设我需要一个长度为 10 的数组,所以它变成: [1,2,3,4,1,2,3,4,1,2]

所以我需要以相同的顺序使用与列表中相同的值来扩展列表

returnString = the array or string to return with extended elements
array = the basic array which needs to be extended
length = desired length
Run Code Online (Sandbox Code Playgroud)

编辑:

returnString = ""
array = list(array)
index = 0
while len(str(array)) != length:
    if index <= length:
        returnString += array[index]
        index += 1
    else:
        toPut = index % length
        returnString.append(array[toPut])
        index += 1
return returnString
Run Code Online (Sandbox Code Playgroud)

python arrays repeat

0
推荐指数
1
解决办法
758
查看次数

编写一个将字符串重复 n 次并将每次重复与另一个字符串分开的函数

我正在尝试编写一个需要 3 个输入的函数:一个字符串(已命名word)、一个整数(已命名n)、另一个字符串(已命名delim',然后该函数必须重复命名word n时间的字符串(这很容易),并且在每次重复之间它都有插入名为 的字符串delim

我知道这段代码有效:

print('me', 'cat', 'table', sep='&')
Run Code Online (Sandbox Code Playgroud)

但这段代码没有:

print(cat*3, sep='&')
Run Code Online (Sandbox Code Playgroud)

我写的代码几乎没用,但我还是会发布它——可能还有我不知道的其他错误或不准确之处。

def repeat(word, n, delim):
    print(word*n , sep=delim)

def main():
    string=input('insert a string:  ')
    n=int(input('insert number of repetition:  '))
    delim=input('insert the separator:  ')

    repeat(string, n, delim)

main()
Run Code Online (Sandbox Code Playgroud)

例如,给定以下输入:

word='cat', n=3, delim='petting'
Run Code Online (Sandbox Code Playgroud)

我希望该程序回馈:

catpettingcatpettingcat
Run Code Online (Sandbox Code Playgroud)

python string repeat python-3.x

0
推荐指数
2
解决办法
54
查看次数

如何用空格多次重复字符串?

我想用 n 次传递一个字符串以用空格重复它,我的代码如下所示:

def repeating(word, n):
  return word * n
Run Code Online (Sandbox Code Playgroud)

我希望输出看起来像:

hello hello hello
Run Code Online (Sandbox Code Playgroud)

每个字符串之间有空格。

python repeat

0
推荐指数
1
解决办法
70
查看次数

正则表达式,没有最大限制

我需要一个接受所有类型字符(字母,数字和所有特殊字符)的正则表达式,并且miniumum字符数应为15,并且对最大字符没有限制.

regex asp.net string repeat

-1
推荐指数
1
解决办法
2418
查看次数

如何在不使用while循环的情况下在python3中重复一个函数?

我在python中有一个函数需要不断运行并检查一些变量.目前我有一个while循环,一切都顺利运行,直到我想使用pyqt小部件,最终导致灾难.

我已经在stackoverflow中的其他线程上找到了twisted.internet模块,但我不能让它在python3上运行.

是否有另一个模块允许我重复某个函数在python3中每0.01秒运行一次而不会闲置我的代码?

python repeat python-3.x

-1
推荐指数
1
解决办法
640
查看次数

使用另一个列表中的n重复列表中的元素n次

也许这之前被问过,在这种情况下我会删除这个问题,但我有两个列表:

occurence_list = [1, 2, 3, 4, 5]
value_list = [10, 20, 30, 40, 50]
Run Code Online (Sandbox Code Playgroud)

我希望每个值看起来与另一个列表中相同索引的值相同:

result = [10, 20, 20, 30, 30, 30, 40, 40, 40, 40, 50, 50, 50, 50, 50]
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?

python list repeat

-1
推荐指数
1
解决办法
452
查看次数

Delphi7,使用Tmediaplayer重复声音

我正在使用delphi7.我想在我的程序中放一首歌,但我不希望它永远不会结束.我尝试使用计时器,但它没有播放音乐:

procedure TForm1.FormCreate(Sender: TObject);
begin
timer1.enabled:=true;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
var playsound,destination:string;
begin

destination:=paramstr(0); 
playsound:=extractfilepath(destination)+'Soundtrack\play.wma';

mediaplayer1.FileName:=playsound;                
mediaplayer1.Open;
mediaplayer1.Play;                        //USING TMEDIAPLAYER

end;
Run Code Online (Sandbox Code Playgroud)

此代码中没有语法错误,但是歌曲没有运行,也许计时器不适用于该作业.我该怎么办?谢谢

delphi audio repeat media-player

-2
推荐指数
1
解决办法
2448
查看次数

用重复值填充熊猫数据框

我在 R 中有这个代码

a <- c(NA)
a<- matrix(c(a), nrow = 80)
a<-as.data.frame(a)

a[ c(T,F,F,F), ] <- "aaa"
a[ c(F,T,F,F), ] <- "bbb"
a[ c(F,F,T,F), ] <- "ccc"
a[ c(F,F,F,T), ] <- "ddd"
Run Code Online (Sandbox Code Playgroud)

如何在 python 中将它复制为熊猫数据框?

str(a)
Run Code Online (Sandbox Code Playgroud)

'data.frame':80 个观察。共 1 个变量:

$ V1: chr "aaa" "bbb" "ccc" "ddd" ...

python repeat dataframe pandas

-2
推荐指数
1
解决办法
5612
查看次数