小编Ahm*_*san的帖子

使用 JavaScript RegEx 从 html 标签中删除不必要的属性

我是正则表达式的新手,尝试过滤 HTML 标签,仅保留必需的 (src / href / style) 属性及其值,并删除不必要的属性。在谷歌搜索时,我发现一个正则表达式只保留“src”属性,因此我修改后的表达式如下:

<([a-z][a-z0-9]*)(?:[^>]*(\s(src|href|style)=['\"][^'\"]*['\"]))?[^>]*?(\/?)>
Run Code Online (Sandbox Code Playgroud)

它工作正常,但唯一的问题是,如果一个标签包含多个必需属性,那么它只保留最后一个匹配的单个属性并丢弃其余的属性。

我正在尝试清理以下文本

<title>Hello World</title>
<div fadeout"="" style="margin:0px;" class="xyz">
    <img src="abc.jpg" alt="" />
    <p style="margin-bottom:10px;">
        The event is celebrating its 50th anniversary K&ouml;&nbsp;
        <a style="margin:0px;" href="http://www.germany.travel/">exhibition grounds in Cologne</a>.
    </p>
    <p style="padding:0px;"></p>
    <p style="color:black;">
        <strong>A festival for art lovers</strong>
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

https://regex101.com/#javascript使用上述表达式作为<$1$2$4>替换字符串并获得以下输出:

<title>Hello World</title>
<div style="margin:0px;">
    <img src="abc.jpg"/>
    <p style="margin-bottom:10px;">
        The event is celebrating its 50th anniversary K&ouml;&nbsp;
        <a href="http://www.germany.travel/">exhibition grounds in Cologne</a>.
    </p>
    <p style="padding:0px;"></p>
    <p …
Run Code Online (Sandbox Code Playgroud)

html javascript regex

3
推荐指数
1
解决办法
3778
查看次数

如何获得特定范围内的汽车数量

我正在尝试模拟一种VANET场景,在这种场景中,如果道路被阻塞,那么在特定时间之后,汽车会广播一条消息,其中包括被阻塞的roadId和它周围100米处的车辆数量。

在TraCIDemo11p应用程序中,当汽车停下来超过10秒钟时,它将节点颜色更改为红色(以表示事故),并向包含阻塞道路ID的其他汽车发送消息,所有这些操作均在handlePositionUpdate方法中完成:

findHost()->getDisplayString().updateWith("r=16,red");
sentMessage = true;

WaveShortMessage* wsm = new WaveShortMessage();
populateWSM(wsm);
wsm->setWsmData(mobility->getRoadId().c_str());

//host is standing still due to crash
if (dataOnSch) {
    startService(Channels::SCH2, 42, "Traffic Information Service");
    //started service and server advertising, schedule message to self to send later
    scheduleAt(computeAsynchronousSendingTime(1,type_SCH),wsm);
}
else {
    //send right away on CCH, because channel switching is disabled
    sendDown(wsm);
}
Run Code Online (Sandbox Code Playgroud)

可以通过更新.ini文件中的maxInterfDist值来设置100m的限制

*.connectionManager.maxInterfDist = 100m
Run Code Online (Sandbox Code Playgroud)

现在我的问题是如何获取车辆数量和100m的面积,我有一个想法,这将使用TraCI来完成,最有可能使用LaneAreaDetector的getJamLengthVehicle来完成,但是我不知道如何做到这一点。他们任何等效的方法还是我看错了方向?

c++ simulation omnet++ veins sumo

1
推荐指数
1
解决办法
385
查看次数

标签 统计

c++ ×1

html ×1

javascript ×1

omnet++ ×1

regex ×1

simulation ×1

sumo ×1

veins ×1