正则表达式中\A,\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
温馨提示:答案为网友推荐,仅供参考
相似回答