Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-03-2021 12:36 PM
Hi all,
I'm struggling with APOC text functions to filter nodes by matching a string with a slice of a string in nodes' attributes.
In python, I can easily do that by treating strings as arrays:
test = "a test string"
'test' == test[2:6]
True
How can I accomplish the same results with Cypher/APOC ? That is, do a partial match in parts of a string?
Solved! Go to Solution.
05-03-2021 01:39 PM
Hi, depending on whether you need the exact place of the string or not you have several options:
RETURN test CONTAINS "test" // returns true
RETURN apoc.text.indexOf(test, 'test') // returns 2
STARTS WITH
or ENDS WITH
Hope this helps
05-03-2021 01:39 PM
Hi, depending on whether you need the exact place of the string or not you have several options:
RETURN test CONTAINS "test" // returns true
RETURN apoc.text.indexOf(test, 'test') // returns 2
STARTS WITH
or ENDS WITH
Hope this helps
05-03-2021 02:35 PM
Also CONTAINS
works too. The advantage of STARTS WITH, ENDS WITH, and CONTAINS is that these are index-friendly, an index on the property allows leveraging of the index.
While we can't currently do index-based slicing of a string in the way that we can for lists (I'm pushing for this, myself), we do have the built-in substring() function.
All the sessions of the conference are now available online