2016-08-01 47 views

回答

1

有2個問題:

  1. {,16}的字符匹配的{,16}從字面上看,你應該使用{0,16}
  2. 你有2個量詞所以不是.+{,16}你應該使用.{0,16}

正則表達式應該爲你服務:

$regex = '/^.{0,16}$/'; // will match empty input also 

RegEx Demo

+0

謝謝you..it worked..bt無法理解什麼是懶惰和貪婪的量詞 –

+0

有懶惰量詞在'^ {0,16} $'。 [在量詞上閱讀這篇很好的文章](http://www.regular-expressions.info/repeat.html) – anubhava