Hello everyone, I'm a stackoverflow novice.
If I have any wrong about asking this question, hope to redress me. :)
If my test string is 'One\nTwo\n\nFour'
,
I use the RegExp /(.)*\n/
in JavaScript,
will match 'One\nTwo\n\n'
not 'One\n', 'Two\n' and '\n'
in my expectation.
And I want to get the result is 'One', 'Two', '' and 'Four'
.
Very thanks @Dalorzo's answer.
'One\nTwo\n\nFour'.split(/\n/g) //outputs ["One", "Two", "", "Four"]
Maybe better could be a split to achieve the same goal? by
With Regex:
'One\nTwo\n\nFour'.split(/\n/) //outputs ["One", "Two", "", "Four"]
or without Regex like:
'One\nTwo\n\nFour'.split('\n') //outputs ["One", "Two", "", "Four"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With