0

I got a regex pattern: (~[A-Z]){10,30} (Thanks to KekuSemau). And I need to edit it, so it will skip 1 letter. So it will be like down below.

Input:    CABBYCRDCEBFYGGHQIPJOK 
Output:    A B C D E F G H I J K
2
  • Perhaps for that input you could match the first character and capture the second character in a group and replace with a whitespace and the capturing group[A-Z]([A-Z])? Commented Jul 30, 2018 at 7:16
  • What's with the ~? Just replace .(.) with ` $1` (space+$1). See it here at regex101. Commented Jul 30, 2018 at 9:24

2 Answers 2

1

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

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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#:

string value = "";
for (int i = 0; i < match.Groups["pick"].Captures.Count; i++)
{
   value = match.Groups["pick"].Captures[0].Value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.