0

the following js regex:

the(.*?)study

selects all words between the words 'the' and 'study', e.g.:

*the assumption that ACE levels are stable, circulating ACE has been shown to be altered in obesity and weight loss. We sought to examine effects of a high-saturated-fat (HF) diet on ACE within the NUtriGenomic Analysis in Twins (NUGAT) study.

regex101 example

how can I select the words between 'the' and 'study' without overlapping, i.e.:

the NUtriGenomic Analysis in Twins (NUGAT) study.

haz
  • 740
  • 1
  • 11
  • 20
  • In the regex, when you put `.*` before `the`, the capturing group will only match `NUtriGenomic Analysis in Twins (NUGAT)`. You can also modify your regex to `.*the\s*(.*?)\s*study` in order to remove spaces from the match. – Sebastian Simon Feb 08 '17 at 08:45
  • 1
    See [my answer](http://stackoverflow.com/a/40556433/3832970). Your pattern can be written as `the((?:(?!the).)*?)study` or `the((?:(?!the|study).)*)study` – Wiktor Stribiżew Feb 08 '17 at 08:45
  • @ Wiktor "Non-greedy string regular expression matching" is fairly a esoteric and cannot be found using search criteria such as select all words/strings between 2 words. But thank you for linking it. – haz Feb 08 '17 at 08:50

0 Answers0