我想將總長度檢查集成到匹配中,不幸的是我只在子組本身的長度匹配中成功。
要求:它應該包含一個字母數字字串,其中包含來自 AZ 的字母以及 0-9 的數字以及 1 個斜線或 1 個空格,但只在中間,不需要捕獲。
^(?:[A-Z0-9] (?:(?:-| )[A-Z0-9] )?)$
^(?:[A-Z0-9] (?:(?:-| )[A-Z0-9] )?){1,11}$
uj5u.com熱心網友回復:
以下是否做你所追求的:
^(?!.{12})[A-Z0-9] (?:[- ][A-Z0-9] )?$
查看在線演示。連字符或空格的使用現在是可選的。不確定你是否希望它是強制性的,如果是這樣:
^(?!.{12})[A-Z0-9] [- ][A-Z0-9] $
uj5u.com熱心網友回復:
如果我理解你的權利(有效字串必須包含至少一個字符A-Z,0-9,/, 而絕不能開始或結束WTH /, ),你可以試試
^(?=.*[A-Z].*)(?=.*[0-9].*)(?=. [\/]. )(?=. [ ]. ).{1,11}$
圖案:
^ - (anchor) start of the string
(?=.*[A-Z].*) - contains A-Z somewhere
(?=.*[0-9].*) - contains 0-9 somewhere
(?=. [\/]. ) - contains /, but in the middle (not first and not last)
(?=. [ ]. ) - contains ' ' (space), but in the middle (not first and not last)
.{1,11} - from 1 to 11 arbitrary characters
$ - (anchor) end of the string
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/398907.html
標籤:正则表达式
