【发布时间】:2021-06-04 07:59:44
【问题描述】:
我需要在我的 svg 文件中检索类似“{ content }”的特定内容
所以我想我需要使用正则表达式,但我不知道该怎么做
test.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}
}
})
预期结果:
- {车库/温度}
- {home/sensors/temp/kitchen}
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/questions/32873100/…
标签: javascript regex svg