I have a map (key, value pairs) and few of these values have line breaks within them (inside double quotes) which is causing issues in CSS.
How can I remove these link breaks (the ones inside double quotes only) using regex find and replace (suitable in JavaScript).
Input:
actionIconTransition: " background-color 0.2s,
color 0.2s, box-shadow 0.2s",
listItemTransition:
" background-color 0.2s,
border-color 0.2s, box-shadow 0.2s",
primeIconFontSize: " 1rem",
divider: " 1px solid #dee2e6",
Expected output:
actionIconTransition: " background-color 0.2s,color 0.2s, box-shadow 0.2s",
listItemTransition:
" background-color 0.2s,border-color 0.2s, box-shadow 0.2s",
primeIconFontSize: " 1rem",
divider: " 1px solid #dee2e6",
I have tried many regexes but they are either removing line breaks in last two lines too, or don't do anything at all.
Use
let test_str = `actionIconTransition: " background-color 0.2s,
color 0.2s, box-shadow 0.2s",
listItemTransition:
" background-color 0.2s,
border-color 0.2s, box-shadow 0.2s",
primeIconFontSize: " 1rem",
divider: " 1px solid #dee2e6",`
console.log(test_str.replace(/"[^"]*"|'[^']*'/g, (z) => z.replace(/[\r\n]+/g, '')))
I.e. remove carriage return and line feed characters between quotes only.
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