开发者

Node.js: Regex to make sure the string is the first in the line

开发者 https://www.devze.com 2023-03-09 05:42 出处:网络
How can I make sure that the string \"To:\" is at the beginning of the line and not at the middle or end?

How can I make sure that the string "To:" is at the beginning of the line and not at the middle or end?

This is what I have: result.match(/To\:开发者_如何转开发(.*)/)[1].replace(/^\s+/, '');


You want the ^ anchor, i.e. /^.../

Keep in mind that this matches the start-of-string, which is fine if you read line by line. In case you have multiple lines (i.e. newlines) in your string and you want to allow matches on any such line, use the m ("multi-line") modifier: /^.../m

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号