[英]C++: Regex pattern
I got a regex pattern: (~[AZ]){10,30} (Thanks to KekuSemau). 我得到了一个正则表达式模式:(〜[AZ]){10,30}(感谢KekuSemau)。 And I need to edit it, so it will skip 1 letter.
而且我需要对其进行编辑,因此它将跳过1个字母。 So it will be like down below.
因此,它将像下面这样。
Input: CABBYCRDCEBFYGGHQIPJOK
Output: A B C D E F G H I J K
Just match two letters each iteration but only capture the second part. 每次迭代仅匹配两个字母,但仅捕获第二部分。
(?:~[A-Z](~[A-Z])){5,15}
live: https://regex101.com/r/pIAxH8/1 直播: https : //regex101.com/r/pIAxH8/1
I cut the repetition count (the bit inside the {}'s) by half since the new regex is matching two at a time. 由于新的正则表达式一次匹配两个,所以我将重复计数({}中的位)减少了一半。
The ?:
in (?:...)
bit disables capturing of the group. ?:
in (?:...)
位禁用捕获组。
In regex only, there is no way you can achieve this directly. 仅在正则表达式中,您无法直接实现此目的。 But you can do this in code:
但是您可以在代码中执行此操作:
Use following regex: 使用以下正则表达式:
(.(?<pick>[A-Z]))+
and in code make a loop on "captures" of desired group, like in c#: 然后在代码中对所需组的“捕获”进行循环,例如在c#中:
string value = "";
for (int i = 0; i < match.Groups["pick"].Captures.Count; i++)
{
value = match.Groups["pick"].Captures[0].Value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.