Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

The SDK database database constructs regular expressions


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Database.RegExp

Construct a regular expression that only needs to be used if the normal js regular expression cannot be satisfied

Options parameter description

Options support the three flags i, m, s, note that JavaScript native positive objects are constructed with only i, m two flags, so you must use db when using s this flag. T he RegExp constructor constructs a positive object. The meaning of flag can be found in the table below:

flag Description
Case is insensitive
M Cross-line matching; ^ $
s Allows . to match all characters, including line breaks

Example of basic usage

// 原生 JavaScript 对象
db.collection('todos').where({
  description: /miniprogram/i
})

// 数据库正则对象
db.collection('todos').where({
  description: db.RegExp({
    regexp: 'miniprogram',
    options: 'i',
  })
})

// 用 new 构造也是可以的
db.collection('todos').where({
  description: new db.RegExp({
    regexp: 'miniprogram',
    options: 'i',
  })
})