title: Regex for SPARQL
body: <p>I have downloaded dbpedia_quotationsbook.zip from <a href="http://downloads.dbpedia.org/1.0/" rel="nofollow">dbpedia</a> which contains dbpedia_quotationsbook.nt triplestore.</p>
  
  <p>In this triplestore </p>
  
  <blockquote>
    <p>subject is authorname<br>
         predicate is "sameas"<br>
    object is authorcode</p>
  </blockquote>
  
  <p>I have tried this querying triplestore using JENA , simple queries are running.</p>
  
  <p>Now <strong>I want all authorcode whose authorname matches partially with given string</strong> .
  So I tried following query </p>
  
  <pre><code>select ?code
  where
  {
  
  FILTER regex(?name, "^Rob")  &lt;http://www.w3.org/2002/07/owl#sameAs&gt; ?code.
  
  }
  </code></pre>
  
  <blockquote>
    <p>above query should return all authorcodes whose authorname contains
    "Rob"</p>
  </blockquote>
  
  <p>I am getting following exception </p>
  
  <pre><code>Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " "." ". "" at line 5, column 74.
  Was expecting one of:
      &lt;IRIref&gt; ...
      &lt;PNAME_NS&gt; ...
      &lt;PNAME_LN&gt; ...
      &lt;BLANK_NODE_LABEL&gt; ...
      &lt;VAR1&gt; ...
      &lt;VAR2&gt; ...
      "true" ...
      "false" ...
      &lt;INTEGER&gt; ...
      &lt;DECIMAL&gt; ...
      &lt;DOUBLE&gt; ...
      &lt;INTEGER_POSITIVE&gt; ...
      &lt;DECIMAL_POSITIVE&gt; ...
      &lt;DOUBLE_POSITIVE&gt; ...
      &lt;INTEGER_NEGATIVE&gt; ...
      &lt;DECIMAL_NEGATIVE&gt; ...
      &lt;DOUBLE_NEGATIVE&gt; ...
      &lt;STRING_LITERAL1&gt; ...
      &lt;STRING_LITERAL2&gt; ...
      &lt;STRING_LITERAL_LONG1&gt; ...
      &lt;STRING_LITERAL_LONG2&gt; ...
      "(" ...
      &lt;NIL&gt; ...
      "[" ...
      &lt;ANON&gt; ...
  
      at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102)
      at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53)
      at com.hp.hpl.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:34)
      at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:148)
      at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:80)
      at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:53)
      at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:41)
      at rdfcreate.NewClass.query(NewClass.java:55)
      at rdfcreate.NewClass.main(NewClass.java:97)
  </code></pre>
  
  <p>Jena Code</p>
  
  <pre><code>import com.hp.hpl.jena.query.Dataset;
  import com.hp.hpl.jena.query.Query;
  import com.hp.hpl.jena.query.QueryExecution;
  import com.hp.hpl.jena.query.QueryExecutionFactory;
  import com.hp.hpl.jena.query.QueryFactory;
  import com.hp.hpl.jena.query.QuerySolution;
  import com.hp.hpl.jena.query.ResultSet;
  import com.hp.hpl.jena.rdf.model.Model;
  import com.hp.hpl.jena.tdb.TDBFactory;
  import com.hp.hpl.jena.util.FileManager;
  
  /**
   *
   * @author swapnil
   */
  public class NewClass {
      String read()
          {
                 final String tdbDirectory = "C:\\TDBLoadGeoCoordinatesAndLabels"; 
  
  
      String dataPath = "F:\\Swapnil Drive\\Project Stuff\\Project data 2015 16\\Freelancer\\SPARQL\\dbpedia_quotationsbook.nt";
  
  
       Model tdbModel = TDBFactory.createModel(tdbDirectory);
               /*Incrementally read data to the Model, once per run , RAM &gt; 6 GB*/
  
               FileManager.get().readModel( tdbModel, dataPath, "N-TRIPLES");
  
               tdbModel.close();
  
               return tdbDirectory;
          }
  
         void query(String tdbDirectory, String query1)
         {
  
  
      Dataset dataset = TDBFactory.createDataset(tdbDirectory);
                Model tdb = dataset.getDefaultModel();
                Query query = QueryFactory.create(query1);
                QueryExecution qexec = QueryExecutionFactory.create(query, tdb);
                /*Execute the Query*/
                  ResultSet results = qexec.execSelect();
                  System.out.println(results.getRowNumber());
                  while (results.hasNext()) {
                        // Do something important
                      QuerySolution qs =   results.nextSolution();
                qs.toString();
                      System.out.println("sol "+qs);
                  }
                     qexec.close();
                 tdb.close() ;
         }
  
       public static void main(String[] args) {
  
              NewClass nc = new NewClass();
           String tdbd=    nc.read();
            nc.query(tdbd, "select ?code\n" +
      "WHERE\n" +
      "{\n" +
      "&lt;http://dbpedia.org/resource/Robert_H._Schuller&gt; &lt;http://www.w3.org/2002/07/owl#sameAs&gt; ?code.\n" +
      "}");
  
  
         }
  
  }
  
  }
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <blockquote>
    <p><em>sol ( ?code = <a href="http://quotationsbook.com/author/6523" rel="nofollow">http://quotationsbook.com/author/6523</a> )</em></p>
  </blockquote>
  
  <p>Above query gives me code of the given author.</p>
  
  <p>Please help me on this</p>