Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between REGEXP_CONTAINS and REGEXP_LIKE in N1QL?

Tags:

couchbase

n1ql

On the Couchbase documentation

https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/patternmatchingfun.html

I saw that:

REGEXP_CONTAINS(expression, pattern)
Returns True if the string value contains the regular expression pattern.

REGEXP_LIKE(expression, pattern)
Returns True if the string value contains the regular expression pattern.

Is there any difference between this functions or one is an alias for another?

like image 200
Andrei Lupuleasa Avatar asked Mar 06 '19 10:03

Andrei Lupuleasa


Video Answer


1 Answers

REGEXP_LIKE() requires that the expression exactly match the pattern. REGEXP_CONTAINS() is less restrictive; the expression only has to contain something that matches the pattern.

This query illustrates the difference. Note that the pattern being searched for is the second parameter to the function.

select REGEXP_CONTAINS("  foof  ", "foof") as contains, REGEXP_LIKE("  foof  ", "foof") as `like`

[
  {
    "contains": true,
    "like": false
  }
]
like image 139
Johan Larson Avatar answered Jan 01 '23 01:01

Johan Larson