模板文字中的正则表达式转义字符

问题描述

我正在尝试将mapql-constraint-directive与阿波罗graphql服务器一起使用。 我需要把reg。像这样的模板文字中的表达式

php://input

这对我不起作用。没有匹配。正则表达式是正确的。该示例使用此 @constraint(pattern:“ ^ [0-9a-zA-Z] $”)*。

所以我意识到我的模板文字typeDefs中的 ^ 05 \ d([-] {0,1})\ d {7} $ 出了问题。

我已经签入Node REPL:

const typeDefs =   gql`
input ClaimInput {
  id: String!
  date: String!
  phone: String @constraint(pattern: "^05\d([-]{0,1})\d{7}$")
  email: String
  invoice: String
  doctorId: String
  therapy: [TherapyInput]
  files: [FileInput]
}
`

当我输入\ d \时,将被忽略。 当我放\\ d时,我有\\ d。不是我所需要的。

如何处理这种情况?

编辑: 我认为问题出在“ gql

当我更改为:

> v = `^05\d([-]{0,1})\d{7}$`
'^05d([-]{0,1})d{7}$'
> v = `^05\\d([-]{0,1})\d{7}$`
'^05\\d([-]{0,1})d{7}$'

我有一个错误: GraphQLError:语法错误:无效的字符转义序列:\ d。

当我更改为

const typeDefs = gql`

input ClaimInput {
  id: String!
  date: String!
  phone: String @constraint(pattern: "^05\\d([-]{0,1})\\d{7}$")
  email: String
  invoice: String
  doctorId: String
  therapy: [TherapyInput]
  files: [FileInput]
}
`

我有同样的错误: GraphQLError:语法错误:无效的字符转义序列:\ d。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)