gpt4 book ai didi

javascript 正则表达式因双引号而失败

转载 作者:行者123 更新时间:2023-11-28 20:30:36 24 4
gpt4 key购买 nike

我有这个js

var race = {
"id": Number( matches[ i ].match( /gt5bspec\.selectEvent\("/(\d+/\d+)"\)/ )[ 1 ] ),
"laps": Number( matches[ i ].match( /<dd class="lap">.+?(\d+)/ )[ 1 ] ),
"maxEntrants": Number( matches[ i ].match( /entry_max.+?\/>(\d+)<\/dd>/ )[ 1 ] ),
"time": Number( matches[ i ].match( /common\/time\/(\d+)\.png/ )[ 1 ] ),
};

它的失败 SyntaxError: 非法字符在“id”行我猜测是由于表达式中的引号。

这里是用于搜索的示例字符串

<dl class="remote_event_list">  <dd class="course_logo"><img src="/common/images/gt5/remote_race/common/courselogo/ed2539fe892d2c52c42a440354e8e3d5.png" width="84"></dd>   <dd class="race_info_minute"><img src="/common/images/gt5/remote_race/common/time/20.png" width="80" height="54" alt=""></dd>   <dd class="entry_max"><img src="/common/images/gt5/remote_race/entry/icon_driver.png" width="20" />16</dd>  <dd class="lap"><span>Vuelta(s):</span>&nbsp;12 (en torno a 20 minutos)</dd>    <dd class="car_image">      <img src="/common/images/gt5/car/thumbnail/0a712318b3b8acc70daeb1ff71d40140.png" width="178" /> </dd>   <dd class="link"><a href="javascript:void(0);" onclick='gt5bspec.selectEvent("/116/1035200")' title="Abt Audi TT-R Touring Car '02 / Circuito de Madrid">&nbsp;</a></dd></dl>

我正在尝试匹配组 1 值/116/1035200

谢谢

最佳答案

//-----------------------v
/gt5bspec\.selectEvent\("/(\d+/\d+)"\)/

我已经标记了未转义的斜杠。如果您想在此处使用斜杠,请使用 \/

关于javascript 正则表达式因双引号而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16496459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com