How to properly define the following regex pattern
using Swagger Node.js annotations?
* reviews_ratings_description:
* type: string
* minimum: 10
* maximum: 50
* pattern: "^[ a-zA-Z0-9](?!,.*?[^\na-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\[\\\]\-^_`{|}~]{1}).*?[a-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\\\\]\-^_`{|}~]$"
Running the code above produces the following error:
{"error":{},"level":"error","message":"uncaughtException: YAMLException: can not read an implicit mapping pair; a colon is missed at line 42, column 159:\n ... \"'’=@()*\\+,\\/;\\[\\\\\\]\\-^_`{|}~]$'\n
Does the pattern
string need to be escaped somehow?
Your Pattern contains ", that can't work.
You have to escape the inner quotes by using a backslash in front like \\".
you need to write it in the following pattern:
pattern: ^([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_\-\+\/=]+)$
and if I take your example you should remove the "
from your regex:
pattern: ^[ a-zA-Z0-9](?!,.*?[^\na-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\[\\\]\-^_`{|}~]{1}).*?[a-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\\\\]\-^_`{|}~]$
TIP: use one of the online regex build/test -> https://regex101.com/ (my favorite)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.