Michael
How would that look like?
Hm. After further tests, it seems as it is not possible to escape
anything in a regex at all.
E.g. "....WHERE d.name =~/.*a\\.c.*/...."results in a parsing error:
illegal start of value
"START ref=node(0) MATCH ref-[:TEST]->d WHERE d.name =~/.*a\.c.*/ RETURN d"
^
at org.neo4j.cypher.internal.parser.v1_6.CypherParserImpl.parse(CypherParserImpl.scala:65)
at org.neo4j.cypher.CypherParser.parse(CypherParser.scala:42)
This seems like a missing piece: escaping in regular expressions.
Full test code:
@Test
public void regexTest() {
GraphDatabaseService db = neo4j.getGraphDatabaseService();
Node d = db.createNode();
d.setProperty("name", "foo a.c bar");
Node e = db.createNode();
e.setProperty("name", "foo aXc bar");
db.getReferenceNode().createRelationshipTo(d,
DynamicRelationshipType.withName("TEST"));
db.getReferenceNode().createRelationshipTo(e,
DynamicRelationshipType.withName("TEST"));
String query = "START ref=node(0) MATCH ref-[:TEST]->d WHERE
d.name =~/.*a\\.c.*/ RETURN d";
ExecutionEngine engine = new ExecutionEngine(db);
ExecutionResult result = engine.execute(query);
Iterator<Node> n_column = result.columnAs("d");
while (n_column.hasNext()) {
System.out.println(n_column.next().getProperty("name"));
}
}
Best regards,
James
query("START ref=node(0) MATCH ref-[:TEST]->d WHERE d.name =~ {param} RETURN d", map("param",".*a\\.c.*"))
Michael
What does the actual escaped string look like? Any chance to get the
string representation of the query from the ExecutionEngine somehow?
Best regards,
James
Am 3. April 2012 14:32 schrieb Michael Hunger
<michael...@neotechnology.com>:
That works, thanks.
What does the actual escaped string look like? Any chance to get the
string representation of the query from the ExecutionEngine somehow?