^从行开始处匹配,$从行结束处开始匹配。
\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
\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
本文介绍了正则表达式中的边界匹配符号,包括行和字符串的开始与结束匹配。通过实例展示了如何使用这些符号来精确匹配目标文本。
875

被折叠的 条评论
为什么被折叠?



