-1

I have strings, and i want to find in them 2 words: START and END.

START and END always come together (maybe i will have another characters between them, but if i have START, i will have END too).

Between first START and last END, i can have another couples of START and END.

I try to do with regEx source that find the first START and than his own END, and it will return the correct substring between them.


here is the regEx diagram of what i need:

(i need to get the string between the first START to the last END)

regExp diagram

ldoroni
  • 629
  • 1
  • 7
  • 18
  • 2
    You asked the same question yesterday. Why repeat the same question? If you have something to add to clarify, just edit your existing question. – Abhitalks Aug 14 '15 at 14:57
  • Why use regex for this? – Chief Wiggum Aug 14 '15 at 14:58
  • @Abhitalks no one understand me there so i wrote new one, that probably will make people understand me better. if i just was update it, probably no one was read that update. – ldoroni Aug 14 '15 at 15:01
  • That is not how SO works, nor does that increases the chance of visibility. In fact it makes it liable to get closed and deleted. In order to increase user attention, you should try to improve your existing question. – Abhitalks Aug 14 '15 at 15:04

3 Answers3

2

I would just use the simple js indexOf and lastIndexOf instead of a regex:

var outerText = 'something test start something else some more test start end some more end some more'
var s = outerText.indexOf("start");
var e = outerText.lastIndexOf("end");

var innerText = outerText.substring(s+5, e);
Chief Wiggum
  • 2,784
  • 2
  • 31
  • 44
0

First match of following regex is your string.

Regex:

[^start](.*)(end){1}

JavaScript:

// returns "start end "
'start start end end'.match(/[^start](.*)(end){1}/)[1]

Example: https://regex101.com/r/qO2mS5/2

Szymon Toda
  • 4,454
  • 11
  • 43
  • 62
-1

If I understand you, this is what you want.

/START (.*) END/

Example: https://regex101.com/r/vE9bQ1/1

TheNatureBoy
  • 198
  • 1
  • 2
  • 7