正则表达式:每 5 个单词中添加列表中的特定单词 - 随机

正则表达式:每 5 个单词中添加列表中的特定单词 - 随机

我有这个单词表:of, in the, that, as to, can, may, due to the fact that

另外,我还有以下文字/段落:

The teaching methods represent the ways used in the school by the teacher to support the students to discover life, nature, the world, things, science. They are also means by which students' skills, abilities and capacities to act on nature are formed and developed, to use the fruits of knowledge transforming the exterior into interior facilities, forming their character and developing their personality.

我想将列表中的单词插入到文本中的每 5 个单词中,而不考虑 .[点] 句子听起来好不好听、是否有逻辑都无关紧要。单词列表可以随机插入,也可以按所选顺序插入。

输出:

教学方法代表了学校使用的方法在里面由老师支持学生们去探索生活,作为自然、世界、事物、科学。它们也意味着可能哪些学生的技能、能力和由于这个事实对自然采取行动的能力形成和发展,可能利用知识转化的成果作为将外部设施改造成内部设施,在里面形成他们的性格并发展他们的个性。

寻找:(?:\S+\s+){5}\S+\K

替换为: \1may \2if the \3that \4as to

我认为替换并不好。有人能帮助我吗?

答案1

尝试这个:((\w+)[\h+:-]){5}用这个表达 5 次,代表 5 个单词

寻找:(\w+)[\h+:-](\w+)[\h+:-](\w+)[\h+:-](\w+)[\h+:-](\w+)[\h+:-](\w+)[\h+:-](\w+)

替换为:\1 can \2 may \3 that \4 as to \5 of

或者你可以尝试这个公式\w+(?:-\w+)+ (5次)

相关内容