Capturing Part of String
<p>I want to capture part of a string and I know it involves some combination of substring, regex and matches, I'm having a really hard time putting together a decent solution.  Let's say I have a paragraph of text:</p>

<pre><code>String str = "Lorem ipsum dolor [cookie:firstname] adipiscing elit.";
</code></pre>

<p>I would like to capture the text in-between the the : and ] above, "firstname" in this case (the cookie name could be variable length).  One way I suppose is using split:</p>

<pre><code>str = str.split("\\cookie:")[1]");
</code></pre>

<p>then perhaps a str.replace to remove the training "]" - but I'm hoping there's a more elegant way of doing this.  I'm very new to regex, but haven't be successful getting what i need down.</p>

<p>Thanks in advance for any assistance.</p>
