[英]How to write this regex pattern in Swagger?
如何使用 Swagger Node.js 注釋正確定義以下正則表達式pattern
?
* reviews_ratings_description:
* type: string
* minimum: 10
* maximum: 50
* pattern: "^[ a-zA-Z0-9](?!,.*?[^\na-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\[\\\]\-^_`{|}~]{1}).*?[a-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\\\\]\-^_`{|}~]$"
運行上面的代碼會產生以下錯誤:
{"error":{},"level":"error","message":"uncaughtException: YAMLException: can not read an implicit mapping pair; a colon is missed at line 42, column 159:\n ... \"'’=@()*\\+,\\/;\\[\\\\\\]\\-^_`{|}~]$'\n
pattern
字符串是否需要以某種方式轉義?
你的模式包含“,這是行不通的。
你必須使用前面的反斜杠來逃避內部引號,如\\“。
您需要按照以下模式編寫它:
pattern: ^([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_=]+)\.([a-zA-Z0-9_\-\+\/=]+)$
如果我以你為例,你應該從你的正則表達式中刪除"
:
pattern: ^[ a-zA-Z0-9](?!,.*?[^\na-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\[\\\]\-^_`{|}~]{1}).*?[a-zA-Z0-9!”$%&~^&#<>.?:"'’=@()*\+,\/;\\\\]\-^_`{|}~]$
提示:使用在線正則表達式構建/測試之一 -> https://regex101.com/ (我的最愛)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.