Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming that you want to extract the text between the word "Fruits" and the word "Sports" you could use a regular expression with a <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#cg" rel="nofollow noreferrer">capturing group</a>. This way, if a string matches then you still have to extract the <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Matcher.html#group(int)" rel="nofollow noreferrer">group</a> that contains the text that you want.</p> <p>For example:</p> <pre class="lang-java prettyprint-override"><code>Pattern p = Pattern.compile("Fruits(.*?)Sports", Pattern.DOTALL); // The string "Fruits" ------^ ^ ^ ^ // Capture everything in between --^ ^ ^ // The string "Sports" -----------------^ ^ // This tells the regex to treat newlines ^ // like normal characters ---------------------^ </code></pre> <p>See the <a href="http://regexplained.co.uk/#eyJwYXR0ZXJuIjoiRnJ1aXRzKC4qPylTcG9ydHMifQ==" rel="nofollow noreferrer">railroad diagram</a> below:</p> <p><img src="https://i.stack.imgur.com/8xkEU.png" alt="a railroad diagram of the image"></p> <p>Alternatively, you can use a more advanced regular expression using <a href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#special" rel="nofollow noreferrer">positive lookahead and lookbehinds</a>. This means that you can make your regular expression still look for text between the words "Fruit" and "Sports" but not consider those strings themselves as part of the match.</p> <pre class="lang-java prettyprint-override"><code>Pattern p = Pattern.compile("(?&lt;!Fruits).*?(?=Sports)", Pattern.DOTALL); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload