Мне нужно получить определенный контент, подобный этому {content}, в моем файле svg.
Поэтому я думаю, что мне нужно использовать регулярное выражение, но я не знаю, как это сделать.
тест.svg
<svg width="500" height="100">
<text x="47.872" y="11.064" id="smartCar">{garage/temp} °C</text>
<circle id="circle1" cx="20" cy="20" r="10"
style="stroke: none; fill: #ff0000;"/>
<text x="47.872" y="11.064" id="smartCar">{home/sensors/temp/kitchen} °C</text>
</svg>
findContent.js
var fs = require('fs');
const fileContent = fs.readFileSync( "test.svg","UTF-8");
const lines = fileContent.split("\n");
console.log(lines);
lines.forEach((line) => {
const topicMatch = line.match(); //need regex
if (topicMatch) {
console.log(topicMatch[1]) // display all content with syntax {content}
}
})
Ожидаемый результат:
- {гараж/температура}
- {дом/датчики/температура/кухня}