I’m looking to take a string and break it into an array at line breaks (\n) I tried using split but that takes away the delimiter. I need the \n to be kept at the end of each line if it exists. Does something like this already exist or will I need to code it myself?
I’m looking to take a string and break it into an array at line
Share
You can still use it and preserve the line break if you use look-ahead or look-behind in your regex. Check out the best regular expressions tutorial that I know of:
Regex Tutorial
Look-Around section of the Regex Tutorial.
For example:
The look-ahead or look-behind (also called “look-around”) is non-destructive to the characters they match.