<p>I have a file in the following format:</p>

<pre>
Data Data
Data
[Start]
Data I want
[End]
Data
</pre>

<p>I'd like to grab the <code>Data I want</code> from between the <code>[Start]</code> and <code>[End]</code> tags using a Regex. Can anyone show me how this might be done?</p>

[{'answer_id': 1240, 'author': 'Karl Seguin', 'author_id': 34, 'author_profile': 'https://Stackoverflow.com/users/34', 'pm_score': 6, 'selected': False, 'text': "<pre><code>\\[start\\](.*?)\\[end\\]\n</code></pre>\n\n<p>Zhich'll put the text in the middle within a capture.</p>\n"}, {'answer_id': 1243, 'author': 'Xenph Yan', 'author_id': 264, 'author_profile': 'https://Stackoverflow.com/users/264', 'pm_score': 6, 'selected': True, 'text': '<pre><code>\\[start\\]\\s*(((?!\\[start\\]|\\[end\\]).)+)\\s*\\[end\\]\n</code></pre>\n\n<p>This should hopefully drop the <code>[start]</code> and <code>[end]</code> markers as well.</p>\n'}, {'answer_id': 1252, 'author': 'Grant', 'author_id': 30, 'author_profile': 'https://Stackoverflow.com/users/30', 'pm_score': 1, 'selected': False, 'text': "<p>With Perl you can surround the data you want with ()'s and pull it out later, perhaps other languages have a similar feature.</p>\n\n<pre><code>if ($s_output =~ /(data data data data START(data data data)END (data data)/) \n{\n    $dataAllOfIt = $1;      # 1 full string\n    $dataInMiddle = $2;     # 2 Middle Data\n    $dataAtEnd = $3;        # 3 End Data\n}\n</code></pre>\n"}, {'answer_id': 18612, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 2, 'selected': False, 'text': '<p>A more complete discussion of the pitfalls of using a regex to find matching tags can be found at: <a href="http://faq.perl.org/perlfaq4.html#How_do_I_find_matchi" rel="noreferrer">http://faq.perl.org/perlfaq4.html#How_do_I_find_matchi</a>.  In particular, be aware that nesting tags really need a full-fledged parser in order to be interpreted correctly.</p>\n\n<p>Note that case sensitivity will need to be turned off in order to answer the question as stated.  In perl, that\'s the <strong>i</strong> modifier:</p>\n\n<pre><code>$ echo "Data Data Data [Start] Data i want [End] Data" \\\n  | perl -ne \'/\\[start\\](.*?)\\[end\\]/i; print "$1\\n"\'\n Data i want \n</code></pre>\n\n<p>The other trick is to use the <strong>*?</strong> quantifier which turns off the greediness of the captured match.  For instance, if you have a non-matching <strong>[end]</strong> tag:</p>\n\n<pre><code>Data Data [Start] Data i want [End] Data [end]\n</code></pre>\n\n<p>you probably don\'t want to capture:</p>\n\n<pre><code> Data i want [End] Data\n</code></pre>\n'}, {'answer_id': 63313, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 2, 'selected': False, 'text': '<p>While you can use a regular expression to parse the data between opening and closing tags, you need to think long and hard as to whether this is a path you want to go down.  The reason for it is the potential of tags to nest: if nesting tags could ever happen or may ever happen, the language is said to no longer be regular, and regular expressions cease to be the proper tool for parsing it.</p>\n\n<p>Many regular expression implementations, such as PCRE or perl\'s regular expressions, support backtracking which can be used to achieve this rough effect.  But PCRE (unlike perl) doesn\'t support unlimited backtracking, and this can actually cause things to break in weird ways as soon as you have too many tags.  </p>\n\n<p>There\'s a very commonly cited blog post that discusses this more, <a href="http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html" rel="nofollow noreferrer">http://kore-nordmann.de/blog/do_NOT_parse_using_regexp.html</a>  (google for it and check the cache currently, they seem to be having some downtime)</p>\n'}, {'answer_id': 849859, 'author': 'un33k', 'author_id': 103734, 'author_profile': 'https://Stackoverflow.com/users/103734', 'pm_score': 2, 'selected': False, 'text': "<p>Well, if you guarantee that each start tag is followed by an end tag then the following would work.</p>\n\n<pre><code>\\[start\\](.*?)\\[end\\]\n</code></pre>\n\n<p>However, If you have  complex text such as the follwoing:</p>\n\n<pre><code>[start] sometext [start] sometext2 [end] sometext [end]\n</code></pre>\n\n<p>then you would run into problems with regex.</p>\n\n<p>Now the following example will pull out all the hot links in a page:</p>\n\n<pre><code>'/&lt;a(.*?)a&gt;/i'\n</code></pre>\n\n<p>In the above case we can guarantee that there would not be any nested cases of:</p>\n\n<pre><code>'&lt;a&gt;&lt;/a&gt;'\n</code></pre>\n\n<p>So, this is a complex question and can't just be solved with a simple answer.</p>\n"}, {'answer_id': 12761781, 'author': 'PhaZe', 'author_id': 1725440, 'author_profile': 'https://Stackoverflow.com/users/1725440', 'pm_score': 3, 'selected': False, 'text': '<pre><code>$text ="Data Data Data start Data i want end Data";\n($content) = $text =~ m/ start (.*) end /;\nprint $content;\n</code></pre>\n\n<p>I had a similar problem for a while &amp; I can tell you this method works...</p>\n'}, {'answer_id': 18498275, 'author': 'ankitkpd', 'author_id': 1713298, 'author_profile': 'https://Stackoverflow.com/users/1713298', 'pm_score': 0, 'selected': False, 'text': '<p>Refer to this question to pull out text between tags with space characters and dots (<code>.</code>)</p>\n\n<p><code>[\\S\\s]</code> is the one I used </p>\n\n<p><a href="https://stackoverflow.com/questions/8303488/regex-to-match-any-character-including-new-lines">Regex to match any character including new lines</a></p>\n'}, {'answer_id': 25803893, 'author': 'N Murali Mohan', 'author_id': 4033971, 'author_profile': 'https://Stackoverflow.com/users/4033971', 'pm_score': 0, 'selected': False, 'text': '<p>Reading the text with in the square brackets [] i.e.[Start] and [End] and validate the array with a list of values. <b><em>jsfiddle</em></b> <a href="http://jsfiddle.net/muralinarisetty/r4s4wxj4/1/" rel="nofollow">http://jsfiddle.net/muralinarisetty/r4s4wxj4/1/</a></p>\n\n<pre><code>var mergeFields = ["[sitename]",\n                   "[daystoholdquote]",\n                   "[expires]",\n                   "[firstname]",\n                   "[lastname]",\n                   "[sitephonenumber]",\n                   "[hoh_firstname]",\n                   "[hoh_lastname]"];       \n\nvar str = "fee [sitename] [firstname] \\\nsdfasd [lastname] ";\nvar res = validateMeargeFileds(str);\nconsole.log(res);\n\nfunction validateMeargeFileds(input) {\n    var re = /\\[\\w+]/ig;\n    var isValid;\n    var myArray = input.match(re);\n\n    try{\n        if (myArray.length &gt; 0) {\n            myArray.forEach(function (field) {\n\n                isValid = isMergeField(field);\n\n                if (!isValid){\n                   throw e;                        \n                }\n            });\n        }\n    }\n    catch(e) {        \n    }\n\n    return isValid;\n}\n\nfunction isMergeField(mergefield) {\n    return mergeFields.indexOf(mergefield.toLowerCase()) &gt; -1;\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/1237', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/230/']