title: Value does not live long enough
body: <p>I don't completely understand lifetimes, but I think <code>b</code>'s lifetime will end before <code>self</code>'s.</p>
  
  <p>So, how to edit this code? Do I copy something in memory? If I make a new instance, this lifetime must adhere to this case.</p>
  
  <pre><code>pub struct Formater {
      layout: &amp;'static str,
  }
  
  impl Formater {
      pub fn new(layout: &amp;'static str) -&gt; Formater {
          let regex = Regex::new(r"%\{([a-z]+)(?::(.*?[^\\]))?\}").unwrap();
          let b = regex.replace_all(layout, "{}");
  
          return Formater {
              layout: &amp;b,
          };
      }
  }
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>error: `b` does not live long enough
    --&gt; src/format.rs:16:22
     |
  16 |             layout: &amp;b,
     |                      ^ does not live long enough
  17 |         };
  18 |     }
     |     - borrowed value only lives until here
     |
     = note: borrowed value must be valid for the static lifetime...
  </code></pre>