簡體   English   中英

正數表示0到12之間的正數

[英]Regular Expression for a Positive Number between 0 and 12

我試過沒有運氣搜索互聯網上的正則表達式,檢查:

  • 積極的#
  • 在0到12之間

我需要將它放在這個特定代碼行的括號中

 Regex rxValidHeightInches = new Regex();

任何幫助將不勝感激!

謝謝

這應該工作^(\\d|(1[0-2]))$

var rxValidHeightInches = new Regex("^(\\d|(1[0-2]))$");

試試這個吧。

(?<!-)(\b((1[01])|[1-9])\b)

它匹配1 - 91011 始終排除負數。

-Assert that it is impossible to match the regex below with the match ending at this position (negative lookbehind) «(?<!-)»
---Match the character “-” literally «-»
-Match the regular expression below and capture its match into backreference number 1 «(\b((1[01])|[1-9])\b)»
---Assert position at a word boundary «\b»
---Match the regular expression below and capture its match into backreference number 2 «((1[01])|[1-9])»
------Match either the regular expression below (attempting the next alternative only if this one fails) «(1[01])»
---------Match the regular expression below and capture its match into backreference number 3 «(1[01])»
------------Match the character “1” literally «1»
------------Match a single character present in the list “01” «[01]»
------Or match regular expression number 2 below (the entire group fails if this one fails to match) «[1-9]»
---------Match a single character in the range between “1” and “9” «[1-9]»
---Assert position at a word boundary «\b»

屏幕截圖

在此輸入圖像描述


這一個包括0 - 12

(?<!-)(\b((1[0-2])|[0-9])\b)

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM