开发者

Regular expression to count how many newlines (\n) there are in a string?

I'm trying to find the numbe开发者_运维知识库r of newlines (\n) in a string using the Actionscript 3.0 RegExp engine. Using the string.match function and RegExp("\n","g") does not find the newlines in a string which contains newlines. Is there something I need to add to the pattern or something else that I am missing?


Try using match(/\r?\n/g). It looks like the match() functionality for JavaScript is equal that of ActionScript.


Try the following:

match(/$/mg).length
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜