开发者

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

开发者 https://www.devze.com 2023-02-03 07:02 出处:网络
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 newli

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

精彩评论

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