-1

I want to find a range of characters with a specified start, end and a minimum length.

For example: From the sequence select a range witch starts with a and ends with c and contains 5 or more characters.

The sequence: dabbcbcbabce

I'm trying to get this result: abbcbc

The regex what I'm first tried: a(.*?)c and the result of that: abbc.

And the second: a(.*)c and the result of that: abbcbcbabc.

Max
  • 396
  • 4
  • 13
  • @WiktorStribiżew *starts with a and ends with c and contains 5 or more characters* means the count of 5 *includes* the a and c, so `a.{3,}?c` – Bohemian May 27 '20 at 20:37

1 Answers1

2
a.{3,}?c

Literal match a, then 3 characters until character c found. This gives the total pattern 5 characters - it wasn't clear to me from the question if the start and end should be included in the character count - I have included them.

Similarly, I've not put anything in a capture group - it's known the match will always start with a and end with c, it's just a matter of deciding if these should be included or not and placing the brackets appropriately.

Link to regex101

James Morris
  • 4,867
  • 3
  • 32
  • 51