title: Regex: matching up to the first occurrence of a word
body: <p>What is wrong with :</p>
  
  <pre><code>/(?&lt;={).+(?=public)/s
  </code></pre>
  
  <p>full text</p>
  
  <pre><code>class WeightConvertor {
  
  private:
      double gram;
      double Kilogram;
      double Tonnes;
      void SetGram(double);
      void SetKiloGram(double);
      void SetTonnes(double);
  matching end
  
  public:
      WeightConvertor();
      WeightConvertor(double, double, double);
      ~WeightConvertor();
      void SetWeight(double, double, double);
      void GetWeight(double&amp;, double&amp; ,double&amp;);
      void PrintWeight();
      double TotalWeightInGram();
  
  public:
  
  };
  </code></pre>
  
  <p>how can i match only this text :</p>
  
  <pre><code>private:
      double gram;
      double Kilogram;
      double Tonnes;
      void SetGram(double);
      void SetKiloGram(double);
      void SetTonnes(double);
  matching end
  </code></pre>