Ruby正則表達式的^&和\A\z\Z的區別

^從行開始處匹配,$從行結束處開始匹配。
\A從字符串開始處匹配,\Z從字符串結束處匹配。


例如:

("this is\nthe time",/^the/) =>this is\n<<the>> time
("this is\nthe time",/is$/) =>this <<is>>\nthe time
("this is\nthe time",/\Athis/) =><<this>> is\nthe time
("this is\nthe time",/\Athe/) =>no match
("this is\nthe time",/time\Z/) =>this is\nthe <<time>>
("this is\nthe time",/time\z/) =>this is\nthe <<time>>
("this is\nthe time",/is\Z/) =>no match
("this is\nthe time",/is\z/) =>no match

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章