user6862: I am communicating with the esp8266 WiFi module using Arduino. The module returns GET requests from other clients. They will be of the form 
GET /101011 HTTP/1.1\r\nHost...

I wish to extract only the 101011 from the received serial data and discard the rest. I came up with this small chunk of code to test it by sending data from my laptop.
This is the code:
String s;

void setup() {

  Serial.begin(9600);
}

void loop() {

  if(Serial.available())
  {
    Serial.println("Inside");
    Serial.find("/");
    s = Serial.readStringUntil(' ');
    Serial.println(s);
    // Discard the rest of the data . Snippet from Jeremy Blum's Blog

    while(Serial.available()>0) Serial.read(); 

  }

}

Jeremy's Blog 
But when I run this using the input GET /101011 HTTP/1.1\r\n the output produced is 
Inside
101011
Inside
1.1\r\n

Why is Serial.available() returning true even after reading everything? How to discard the rest of data from the serial input buffer?

user10794: One possible approach is to read and discard everything for a fixed time, like a second. For example:
unsigned long now = millis ();
while (millis () - now < 1000)
  Serial.read ();  // read and discard any input

I'm not a big fan of trying to "flush the input buffer". How do you know if a second is long enough? Or maybe it is too long? You are better off reading to some known delimiter.

6862: <p>I am communicating with the esp8266 WiFi module using Arduino. The module returns GET requests from other clients. They will be of the form </p>

<pre><code>GET /101011 HTTP/1.1\r\nHost...
</code></pre>

<p>I wish to extract only the <code>101011</code> from the received serial data and discard the rest. I came up with this small chunk of code to test it by sending data from my laptop.</p>

<p>This is the code:</p>

<pre><code>String s;

void setup() {

  Serial.begin(9600);
}

void loop() {

  if(Serial.available())
  {
    Serial.println("Inside");
    Serial.find("/");
    s = Serial.readStringUntil(' ');
    Serial.println(s);
    // Discard the rest of the data . Snippet from Jeremy Blum's Blog

    while(Serial.available()&gt;0) Serial.read(); 

  }

}
</code></pre>

<p><a href="http://www.jeremyblum.com/2011/02/07/arduino-tutorial-6-serial-communication-and-processing/" rel="nofollow">Jeremy's Blog</a> </p>

<p>But when I run this using the input <code>GET /101011 HTTP/1.1\r\n</code> the output produced is </p>

<pre><code>Inside
101011
Inside
1.1\r\n
</code></pre>

<p>Why is <code>Serial.available()</code> returning <code>true</code> even after reading everything? How to discard the rest of data from the serial input buffer?</p>
 10794: <p>One possible approach is to read and discard everything for a fixed time, like a second. For example:</p>



<pre class="lang-C++ prettyprint-override"><code>unsigned long now = millis ();
while (millis () - now &lt; 1000)
  Serial.read ();  // read and discard any input
</code></pre>

<p>I'm not a big fan of trying to "flush the input buffer". How do you know if a second is long enough? Or maybe it is too long? You are better off reading to some known delimiter.</p>
