I have a variable text
like this:
"Lorem ipsum dolor sit amet; consetetur sadipscing elitr; sed diam nonumy eirmod tempor "invidunt; ut labore" et dolore magna aliquyam erat/ sed diam voluptua."
What I would like to do is replace all symbols from an array:
var symbolsToreplace = [';', '/', '.']
to a comma. Also What I would like to do is NOT to replace anything within quotes, so all symbols stay the same. Here is Regex to detect quotes:
var detectQuotes = /"([^"]*)"/g;
For now I have achieved one part of task (here I replace all the symbols from an array to ','):
symbolsToreplace.map(function (s) {
if(text.indexOf(s) !== -1 ) {
text.replace(s, ',');
}
})
How could I apply the Regex detectQuotes
, so thre symbols inside the quotes will be ignored?
.replace(/"([^"]*)"|[;.\/]/g, function($0,$1) { return $1 ? $0 : ',';})
- Wiktor Stribiżew