<p>How can I create a regular expression that will grab delimited text from a string?  For example, given a string like </p>

<pre><code>text ###token1### text text ###token2### text text 
</code></pre>

<p>I want a regex that will pull out <code>###token1###</code>.  Yes, I do want the delimiter as well.  By adding another group, I can get both:</p>

<pre><code>(###(.+?)###)
</code></pre>

```
```
/###(.+?)###/
```
```
if you want the ###'s  then you need
```
```
/(###.+?###)/
```
```
the
?
means non greedy, if you didn't have the
?
, then it would grab too much.
e.g.
```
'###token1### text text ###token2###'
```
would all get grabbed.
My initial answer had a * instead of a +.  * means 0 or more.  + means 1 or more.  * was wrong because that would allow ###### as a valid thing to find.
For playing around with regular expressions. I highly recommend
http://www.weitz.de/regex-coach/
for windows.  You can type in the string you want and your regular expression and see what it's actually doing.
Your selected text will be stored in \1   or $1 depending on where you are using your regular expression.