+4  A: 

No need for regular expressions. Simply match any string where the first seven characters are "mailto:".

If you insist on using regular expressions, the expression would be "mailto:.*". If you only want to keep what is after the "mailto:", it would be "mailto:(.*)"

Bryan Oakley
+1 Could you please look at the regex 2
Yatendra Goel
Do you really want to use regex to pull apart a query string? There are libraries specifically designed to do that which will properly handle all the edge cases.
Bryan Oakley
For the second case, see http://stackoverflow.com/questions/2261222/how-to-use-regular-expressions-to-extract-information-from-mailto-links/2261448#2261448
Daniel
A: 
  1. mailto:.+ or mailto:[^\s]+
  2. mailto:.+?\?(.+) or mailto:[^\s]+?\?[^\s]+
splix
+1  A: 

For first you can use String.startsWith(String prefix)

And second maybe trim string for "?" then use String.split("&|="); and you hav array with [ subject, Indian, body, hello]

http://java.sun.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String)

den bardadym
+1  A: 

Regex really isn't necessary for this. A simple String.startsWith would suffice for the first match and you could use the URL class to extract the query.

String string = "mailto:[email protected]?subject=Indian&body=hello";
if (string.startsWith("mailto:")) {
    try {
        URL url = new URL(string);
        String query = url.getQuery(); // Here is your query string.

    } catch (MalformedURLException e) {
        throw new AssertionError("This should not happen: " + e);
    }
}
loliii