想要一个正则表达式来查找 (RE.FINDALL) 个带有两个元音 [aeiou] 的单词,每个其他 (MULTILINE) 字符串上的每个 FOURTH 单词?
Would like a reg ex expression to find (RE.FINDALL) words with two vowels[aeiou] every FOURTH word on every other (MULTILINE) string?
textDoc=
Line 1 "'"Here is my Text which
Line 2 I now have *starred* the words which i would like accounted for"
Line 3 I would like the end result to be Lines 3 Words 6.
Line 4.Python Regular expression **rules** have me trying things that
Line 5.I have listed below. All of them are usable but I would like
Line 6 To understand how to customize it for **production** to use."""
//desiredoutput = Lines 3, Words 3
/* This is because the words: starred, rules, and production are on every
other line and they contain more than 2 vowels all while being the fourth
word on the line.*/
我似乎无法将它们全部放在一起,但我正在考虑的一些正则表达式代码目前已经发挥了一些作用:
enumerate, .split. find.All
[aeiou],[aeiou]{2},
textDoc =
numOfLines = len(textDoc.splitlines())
print(numOfLines)
split 将单词列表转换为字符串。我的猜测是我需要一个新字符串,每隔一行每隔四个单词,然后再计算它们以完成我想要的 Lines 3 Words 3
我认为由于回溯,无法用 python 中的一个正则表达式完成,以下解决方案适用于 perl 正则表达式,因为使用了控制动词 (*SKIP)
:
(?:[a-z]+(?:(?!\n)[^a-z])+){3}((?=(?:(?![aeiou])[a-z])*[aeiou](?:(?![aeiou])[a-z])*[^a-z](*SKIP)(?!)|)[a-z]+)
与 python 最接近的因为回溯而无法工作
(?:[a-z]+(?:(?!\n)[^a-z])+){3}((?=(?:(?:(?![aeiou])[a-z])*[aeiou]){2})[a-z]+)
textDoc=
Line 1 "'"Here is my Text which
Line 2 I now have *starred* the words which i would like accounted for"
Line 3 I would like the end result to be Lines 3 Words 6.
Line 4.Python Regular expression **rules** have me trying things that
Line 5.I have listed below. All of them are usable but I would like
Line 6 To understand how to customize it for **production** to use."""
//desiredoutput = Lines 3, Words 3
/* This is because the words: starred, rules, and production are on every
other line and they contain more than 2 vowels all while being the fourth
word on the line.*/
我似乎无法将它们全部放在一起,但我正在考虑的一些正则表达式代码目前已经发挥了一些作用:
enumerate, .split. find.All
[aeiou],[aeiou]{2},
textDoc =
numOfLines = len(textDoc.splitlines())
print(numOfLines)
split 将单词列表转换为字符串。我的猜测是我需要一个新字符串,每隔一行每隔四个单词,然后再计算它们以完成我想要的 Lines 3 Words 3
我认为由于回溯,无法用 python 中的一个正则表达式完成,以下解决方案适用于 perl 正则表达式,因为使用了控制动词 (*SKIP)
:
(?:[a-z]+(?:(?!\n)[^a-z])+){3}((?=(?:(?![aeiou])[a-z])*[aeiou](?:(?![aeiou])[a-z])*[^a-z](*SKIP)(?!)|)[a-z]+)
与 python 最接近的因为回溯而无法工作
(?:[a-z]+(?:(?!\n)[^a-z])+){3}((?=(?:(?:(?![aeiou])[a-z])*[aeiou]){2})[a-z]+)