-2

I've to detect and extract from a string a repeating group of characters and list one part of each captured group.

Here is an example of string to parse: "za e eStartGood1Endds qStartGood2Endsds df"

My Regex is: ".*?(?::Start(.+)End.*?)+"

Expecting groups captured expected: Good1, Good2, etc

My Regex capture is wrong: it seems that (?::Start(.+) is considered as group to capture...

May I miss something? Thanks!

7
  • I guess you just need Start(.*?)End. No idea what your input really looks like. Have you got actual asterisks there or is it formatting? Commented Jul 22, 2016 at 11:25
  • Hi Wiktor no astericks...Only for bold font. Commented Jul 22, 2016 at 11:35
  • So, use my regex with Regex.Matches. Commented Jul 22, 2016 at 11:38
  • I tell you: use my regex. Regex.Matches(input, @"Start(.*?)End").Cast<Match>().Select(p => p.Groups[1].Value).ToList(); Commented Jul 22, 2016 at 11:47
  • Wiktor, i need a complete Regex syntax to be used in my project. I can't use Link. And this question has no duplicate as far as I know: I need to extract these values several times. Commented Jul 22, 2016 at 12:07

2 Answers 2

0

This regex do the job :

/(?<=Start)(.+?)(?=End)/g
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @baddger, I tried this regex ((?<=Start)(.+?)(?=End))* (without ** for bold font) and i get all characters one by one like this: "z", "a", " ", "e", etc ... Other idea?
try the updated answer :p
Yes, I'm closer now... :) Just need to hide start and end groups... Your regex returns "za e eStart", "Good1", "Endds dqStart", "Good2", "Endsds df". But thanks for this simple syntax with <= and =. I tried to hide them but no return with this one: "(?:<=Start)(.+?)(?:=End)"
Ok, simpler than I thought. You were right Baddger. Regex is: "Start(.+?)End". No need to define a repeating group to get all instances...
so Wiktor Stribiżew say the good answers :p
0

Why not use this pattern: \*{2}Start\*{2}(.*?)\*{2}End\*{2}

For this input string: za e e**Start**Good1**End**ds dq**Start**Good2**End**sds df, it captures Good1 and Good2.

You can play with it here: https://regex101.com/r/dG0dX6/2

1 Comment

Sorry Andrew, you were right too...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.