-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!

Francois
  • 147
  • 1
  • 1
  • 13
  • 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? – Wiktor Stribiżew Jul 22 '16 at 11:25
  • Hi Wiktor no astericks...Only for bold font. – Francois Jul 22 '16 at 11:35
  • So, use my regex with `Regex.Matches`. – Wiktor Stribiżew Jul 22 '16 at 11:38
  • I tell you: use my regex. `Regex.Matches(input, @"Start(.*?)End").Cast().Select(p => p.Groups[1].Value).ToList();` – Wiktor Stribiżew Jul 22 '16 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. – Francois Jul 22 '16 at 12:07
  • Sorry, the way you described the issue, it is a duplicate. Please explain what you need and why you need that, especially why you can't use C# code. – Wiktor Stribiżew Jul 22 '16 at 12:31
  • Wiktor, in my case, I use a general method to call all my regex and I didn't want to add special analyze in that case. And the main difference with potential duplicate is that I need to get ALL instances between Start and End, not only one or first one... – Francois Jul 22 '16 at 12:48

2 Answers2

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

Andrei Tătar
  • 7,872
  • 19
  • 37
0

This regex do the job :

/(?<=Start)(.+?)(?=End)/g
baddger964
  • 1,199
  • 9
  • 18
  • 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? – Francois Jul 22 '16 at 11:45
  • try the updated answer :p – baddger964 Jul 22 '16 at 12:21
  • 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)" – Francois Jul 22 '16 at 12:26
  • Ok, simpler than I thought. You were right Baddger. Regex is: "Start(.+?)End". No need to define a repeating group to get all instances... – Francois Jul 22 '16 at 12:36
  • so Wiktor Stribiżew say the good answers :p – baddger964 Jul 22 '16 at 13:08