# Exact match for string with CONTAINS

**URL:** https://community.neo4j.com/t/exact-match-for-string-with-contains/58632
**Category:** Neo4j Graph Platform
**Tags:** migrated
**Created:** [December 2, 2022, 8:47am UTC](https://community.neo4j.com/t/exact-match-for-string-with-contains/58632 "2022-12-02T08:47:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![takhims](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@takhims](https://community.neo4j.com/u/takhims)
#### Post date: [December 2, 2022, 8:47am UTC](https://community.neo4j.com/t/exact-match-for-string-with-contains/58632/1 "2022-12-02T08:47:51Z")

</div>

Hi all, i have been stuck on an issue related to cypher matching.

So we have multiple nodes which contains a property 'x\_matchKey' and we use this x\_matchKey property to fetch the result with a CONTAINS.

the query goes like that that:  
MATCH (a:person)-\>[r:occupies]-\>(b:position) WHERE b.x\_matchKey contains 'cto' return a. This query is intended to fetch the person whose position is cto. Its was working fine from past few years.

Now there's another node which contains 'director' in the x\_matchKey property.

So when i run this query now, it returns both persons as 'director' also contains 'cto'.

Also, i can't use '=' operator as x\_matchKey contains various terms for a person (Like 'cto, Chief Techniology Officer, EVP, Technical officer'). Basically there are more than two comma separated values for each x\_matchKey.

Is there any way that i can search if a property contains only a **specific word** rather than a **substring**?

I hope i have explained it well, if not please feel free to reply on this thread.

Thanks in advance for all the future suggestions.

---

<div class="post-metadata">

### Author: ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)
#### Post date: [December 2, 2022, 1:10pm UTC](https://community.neo4j.com/t/exact-match-for-string-with-contains/58632/2 "2022-12-02T13:10:37Z")

</div>

Maybe you should store the descriptions as a list instead of a comma concatenated string. You could then determine if the list contains the exact phrase you want.

if that is not an option, you could split the string into a list and determine if the list contains the exact string you want to match.

you could also use a grep search to restrict you results so that it is a whole word from a comma concatenated list.

[https://neo4j.com/docs/cypher-manual/current/functions/string/#functions-split](https://neo4j.com/docs/cypher-manual/current/functions/string/#functions-split)

---

<div class="post-metadata">

### Author: ![ameyasoft](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/ameyasoft/32/32639_2.png) [@ameyasoft](https://community.neo4j.com/u/ameyasoft)
#### Post date: [December 3, 2022, 10:37pm UTC](https://community.neo4j.com/t/exact-match-for-string-with-contains/58632/3 "2022-12-03T22:37:59Z")

</div>

```auto
Try this:
MATCH (a:person)->[r:occupies]->(b:position) WHERE b.x_matchKey contains 'cto,' return a

```

---

<div class="post-metadata">

### Author: ![pohoriljakv](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/pohoriljakv/32/5626_2.png) [@pohoriljakv](https://community.neo4j.com/u/pohoriljakv)
#### Post date: [December 5, 2022, 8:40pm UTC](https://community.neo4j.com/t/exact-match-for-string-with-contains/58632/4 "2022-12-05T20:40:50Z")

</div>

Hi,

It looks very easy, why not

MATCH (a:person)-\>[r:occupies]-\>(b:position) WHERE b.x\_matchKey = 'cto'

Why do not change the architecture to store cto in property "name" and maybe use other id system to have unique condition..... name = 'cto' id = '001' so

MATCH (a:person)-\>[r:occupies]-\>(b:position {matchKey: 'cto'}) RETURN a.name  
or  
MATCH (a:person)-\>[r:occupies]-\>(b:position {name: 'cto'}) RETURN a.name  
or  
MATCH (a:person)-\>[r:occupies]-\>(b:position {id: '001'}) RETURN a.name

Regards

Vaclav
