开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜