This snippet would do what you are asking:
"Paste Multi-line To Single Line":{
"prefix": "pasteMultiLineToSingleLine"
,"body": ["${CLIPBOARD/(\r\n|\n|\r)/ | /g}"]
,"description": "Paste from clipboard replacing every new line with a ' | '"
}
The main difference is in identifying the different possible line ending characters.
Further explanation of the "body":
in case someone else likes to understand the individual parts:
/
${CLIPBOARD}
= Gets the contents of your clipboard.(\r\n|\n|\r)
= This part gets uses regex to get all possible line endings.
|
= read as 'OR'\r\n
= Windows line endings\n
= Unix line endings\r
= Very old Mac systems line ending. Might be able to do without this one. I'm just in the habit of having all cases covered.|
= This is the replacement text.g
= regex option to find and replace all 'global' instances and not just the first occurrence.[1] VSCode Snippet Variables: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables
[2] Stackoverflow ref1: Match linebreaks - \n or \r\n?
[3] Stackoverflow ref2: Difference between \n and \r?