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
精彩评论