-
Hi, i'm trying to create a regex which will bring the second line to the top while at the same time, it will retain a space between the text. Example
To
How would i do that? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
BasicHere is a JavaScript const str = `Text
Second line text`;
const newStr = str.replace(/\r?\n/, ' ');
// Text Second line text If you want more than one line to be replaced, then: const newStr = str.replace(/\r?\n/g, ' '); In Copy PlainText: Find: AdvancedThere are more possible variations which might require adjustment to the regex e.g.
Or ...
This is a more comprehensive regx: const str = `Text
Second line text`;
const newStr = str.replace(/\s*[\r\n]+\s*/g, ' '); |
Beta Was this translation helpful? Give feedback.
-
Thank you @erosman for all the help and the effort you've to explain so thoroughly every sinlge detail or case. I tried some different patterns but none of them worked, yours in the other hand is working perfectly. Thanks again! |
Beta Was this translation helpful? Give feedback.
Basic
Here is a JavaScript
replace()
example:If you want more than one line to be replaced, then:
In Copy PlainText:
Find:
/\r?\n/
Replace: put a single space
Advanced
There are more possible variations which might require adjustment to the regex e.g.
Or ...
This is a more comprehensive regx: